在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元素添加右内边距。
<html> <head> <style> .text { padding-block-start: 20px; padding-inline-start: 30px; margin-block-end: 50px; color: green; background-color: red; width: 300px; font-size: 2rem; } .text1 { width: 300px; font-size: 2rem; padding-block-start: 20px; padding-inline-start: 10px; margin-inline-end: 50px; color: blue; background-color: yellow; } </style> </head> <body> <h3 id="Using-the-i-margins-and-paddings-logical-properties-i-in-CSS"> Using the <i> margins and paddings logical properties </i> in CSS </h3> <div class = "text"> This is a text. </div> <div class = "text1"> This is another text div element. </div> </body> </html>
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.
<html> <head> <style> .sample { border-block-start: 3px dotted blue; border-block-end: 5px solid green; border-inline-start: 10px double red; border-inline-end: 5px groove yellow; padding: 10px; width: 300px; height: 200px; } .left {color: red;} .right {color: yellow;} .top {color: blue;} .bottom {color: green;} </style> </head> <body> <h2 id="Using-the-i-Logical-border-i-properties-in-CSS"> Using the <i> Logical border </i> properties in CSS </h2> <div class = "sample"> Observe the border of the div. <p class = "left"> border inline start </p> <p class = "right"> border inline end </p> <p class = "top"> border block start </p> <p class = "bottom"> border block end </p> </div> </body> </html>
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.
<html> <head> <style> .container { display: flex; flex-direction: row; justify-content: space-between; padding-inline: 40px; width: 500px; background-color: bisque; font-size: 2rem; } .item {flex: 1;} </style> </head> <body> <h3 id="Using-the-i-margin-inline-property-i-to-set-the-inline-margin"> Using the <i> margin-inline property </i> to set the inline margin </h3> <div class = "container"> <div class = "item"> First </div> <div class = "item"> second </div> <div class = "item"> Third </div> </div> </body> </html>
用户学会了在CSS中使用逻辑属性。大多数逻辑属性与边距、内边距和边框有关。然而,与溢出相关的一些逻辑属性也存在,开发人员可以在互联网上查阅。在使用逻辑属性时,用户需要关注“块”和“内联”维度以及“开始”和“结束”方向。
以上是CSS 中的逻辑属性的详细内容。更多信息请关注PHP中文网其他相关文章!

乔纳森·桑普森(Jonathan Sampson)的有趣研究,他观看网络请求浏览器,这是您第一次在新的安装中启动它,并且


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

Dreamweaver Mac版
视觉化网页开发工具

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),