0

0

CSS 中的逻辑属性

王林

王林

发布时间:2023-09-14 10:29:02

|

1399人浏览过

|

来源于tutorialspoint

转载

css 中的逻辑属性

在CSS中,逻辑属性允许开发者根据网页的逻辑结构而不是物理布局来定义样式。这意味着我们可以根据文本方向或内容流应用CSS。

主要使用逻辑属性来设置HTML元素的边距、内边距和边框。它包含了边距、内边距和边框属性的不同变体。

逻辑属性可以根据块级和内联尺寸进行定义。

  • Block dimension − The block dimension represents the perpendicular direction of the content flow. For example, in English text direction is left to right. So, block dimensions handle the top and bottom of the element.

    立即学习前端免费学习笔记(深入)”;

  • 内联尺寸 - 内联尺寸表示与内容或文本方向相同的方向。对于英语来说,左侧和右侧是内联尺寸。

Let’s look at some commonly used logical properties in CSS.

  • Border-block − 它设置了上下边框。

  • Border-inline − 设置左右边框。

  • Border-block-start − It sets the top border.

  • Border-block-end − 它设置了底部边框。

  • Margin-inline − It sets the left and right margins.

  • Padding-inline − It sets the left and right padding.

  • Padding-inline-start − It sets the left padding.

  • Margin-inline-end − It sets the bottom padding.

    腾讯混元
    腾讯混元

    腾讯混元大由腾讯研发的大语言模型,具备强大的中文创作能力、逻辑推理能力,以及可靠的任务执行能力。

    下载
  • Border-inline-end-width − 它设置右边框的宽度。

  • Border-block-start-style − 它设置了顶部边框的样式。

In the above properties, users can observe that we require to use ‘block’ for top and bottom and ‘inline’ for left and right. Also, ‘start’ for left and top, and ‘end’ for right and bottom.

为什么我们应该使用逻辑属性而不是普通的CSS属性?

通过观察上述属性的功能,首先想到的问题是我们是否可以使用普通的CSS属性来实现相同的样式,以及为什么我们应该使用逻辑属性。以下是您的答案。

有时候,我们需要为HTML元素设置左右边距。我们可以使用margin属性的'0 auto'值来实现,或者分别使用margin-left和margin-right的CSS属性。当使用'0 auto'时,如果之前已经应用了上下边距的值,我们也会改变它们的值。因此,最好使用'margin-inline'的CSS属性。

margin: 0 auto;
or
margin-left: auto;
margin-right: auto;
or
margin-inline: auto;

语法

Users can follow the syntax below to use logical properties in CSS.

padding-block-start: value;
margin-inline-end: value;

在上述语法中,我们使用逻辑属性就像使用其他CSS属性一样。

示例1(边距和内边距逻辑属性)

在下面的示例中,我们创建了两个div元素,并在其中添加了文本。在CSS中,我们使用了“padding-block-start”,“padding-inline-start”和“margin-block-end”逻辑CSS属性来为第一个div设置顶部和左侧填充以及底部边距。

此外,我们使用了‘margin-inline-end’逻辑CSS属性来为div元素添加右内边距。



   


   

Using the margins and paddings logical properties in CSS

This is a text.
This is another text div element.

Example 2

In the example below, we have demonstrated the logical CSS properties related to the border. We used the ‘border-block-start’ to apply the top border and the ‘border-block-end’ to apply the bottom border. Furthermore, we used the ‘border-inline-start’ to apply the left border and ‘border-inline-end’ to apply the right border.

In the output, users can observe the different borders for the different sides of the div element.



   


   

Using the Logical border properties in CSS

Observe the border of the div.

border inline start

border inline end

border block start

border block end

Example 3

的翻译为:

示例3

In the example below, we applied the CSS logical properties related to the margin and padding in the flexbox. Here, we have created three div elements inside the container div element. After that, we used the ‘padding-inline’ to apply right and left padding in the container div element.



   


   

Using the margin-inline property to set the inline margin

First
second
Third

用户学会了在CSS中使用逻辑属性。大多数逻辑属性与边距、内边距和边框有关。然而,与溢出相关的一些逻辑属性也存在,开发人员可以在互联网上查阅。在使用逻辑属性时,用户需要关注“块”和“内联”维度以及“开始”和“结束”方向。

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
css
css

css是层叠样式表,用来表现HTML或XML等文件样式的计算机语言,不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。php中文网还为大家带来html的相关下载资源、相关课程以及相关文章等内容,供大家免费下载使用。

522

2023.06.15

css居中
css居中

css居中:1、通过“margin: 0 auto; text-align: center”实现水平居中;2、通过“display:flex”实现水平居中;3、通过“display:table-cell”和“margin-left”实现居中。本专题为大家提供css居中的相关的文章、下载、课程内容,供大家免费下载体验。

262

2023.07.27

css如何插入图片
css如何插入图片

cssCSS是层叠样式表(Cascading Style Sheets)的缩写。它是一种用于描述网页或应用程序外观和样式的标记语言。CSS可以控制网页的字体、颜色、布局、大小、背景、边框等方面,使得网页的外观更加美观和易于阅读。php中文网给大家带来了相关的教程以及文章,欢迎大家前来阅读学习。

753

2023.07.28

css超出显示...
css超出显示...

在CSS中,当文本内容超出容器的宽度或高度时,可以使用省略号来表示被隐藏的文本内容。本专题为大家提供css超出显示...的相关文章,相关教程,供大家免费体验。

539

2023.08.01

css字体颜色
css字体颜色

CSS中,字体颜色可以通过属性color来设置,用于控制文本的前景色,字体颜色在网页设计中起到很重要的作用,具有以下表现作用:1、提升可读性;2、强调重点信息;3、营造氛围和美感;4、用于呈现品牌标识或与品牌形象相符的风格。

757

2023.08.10

什么是css
什么是css

CSS是层叠样式表(Cascading Style Sheets)的缩写,是一种用于描述网页(或其他基于 XML 的文档)样式与布局的标记语言,CSS的作用和意义如下:1、分离样式和内容;2、页面加载速度优化;3、实现响应式设计;4、确保整个网站的风格和样式保持统一。

604

2023.08.10

css三角形怎么写
css三角形怎么写

CSS可以通过多种方式实现三角形形状,本专题为大家提供css三角形怎么写的相关教程,大家可以免费体验。

560

2023.08.21

css设置文字颜色
css设置文字颜色

CSS(层叠样式表)可以用于设置文字颜色,这样做有以下好处和优势:1、增加网页的可视化效果;2、突出显示某些重要的信息或关键字;3、增强品牌识别度;4、提高网页的可访问性;5、引起不同的情感共鸣。

391

2023.08.22

C++ 单元测试与代码质量保障
C++ 单元测试与代码质量保障

本专题系统讲解 C++ 在单元测试与代码质量保障方面的实战方法,包括测试驱动开发理念、Google Test/Google Mock 的使用、测试用例设计、边界条件验证、持续集成中的自动化测试流程,以及常见代码质量问题的发现与修复。通过工程化示例,帮助开发者建立 可测试、可维护、高质量的 C++ 项目体系。

10

2026.01.16

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号