公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

在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> 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> 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> 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 中的逻辑属性的详细内容,更多请关注www.92cms.cn其它相关文章!

分享到:
标签:CSS 属性 逻辑
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定