CSS - inset-inline 属性



CSS inset-inline 属性确定元素在内联方向上的逻辑起始和结束偏移量。它取决于元素的书写模式方向文本方向。它是inset-inline-endinset-inline-start CSS 属性的简写属性。position 属性必须定义才能使该属性显示其效果。

语法

inset-inline: auto | length | percentage | initial | inherit;  

属性值

描述
auto 根据其内容或其他布局因素确定元素的大小。默认值。
length 使用长度单位(例如 px、em、rem 等)设置元素的内联距离。可以使用负值。
percentage 使用相对于其父容器的百分比值设置元素的内联距离。
initial 将属性设置为其默认值。
inherit 从父元素继承该属性。

CSS Inset Inline 属性示例

以下示例说明了使用不同值的 inset-inline 属性。

使用 Auto 值的 Inset Inline 属性

为了允许浏览器根据其他 CSS 属性和应用于元素的布局规则确定内联开始或内联结束边缘的适当偏移量,我们使用 auto 值。这在以下示例中显示。

示例

<!DOCTYPE html>
<html>

<head>
   <style>
      .container {
         border: 2px solid;
         height: 200px;
         width: 300px;
         position: relative;
      }

      .inner-box {
         height: 100%;
         position: absolute;
         background-color: lightgreen;
         inset-inline: auto;
      }
   </style>
</head>

<body>
   <h2>
      CSS inset-inline property
   </h2>
   <h4>
      inset-inline: auto
   </h4>
   <div class="container">
      <div class="inner-box">
         This shows the inset-inline property. Observe 
         how the distance of this green area is changed
         from the inline-start and inline-end.
      </div>
   </div>
</body>

</html>

使用长度值的 Inset Inline 属性

要设置距包含块内联边缘的距离,我们可以使用长度单位(例如 px、em、rem 等)指定距离。最多可以给出两个值。单个值设置内联开始和内联结束距离。如果给出两个值,则第一个值设置内联开始距离,而第二个值设置内联结束距离。这在以下示例中显示。

示例

<!DOCTYPE html>
<html>

<head>
   <style>
      .container {
         border: 2px solid;
         height: 200px;
         width: 300px;
         position: relative;
      }

      .inner {
         height: 100%;
         position: absolute;
         background-color: lightgreen;
      }

      .inner-box1 {
         inset-inline: 10px;
      }

      .inner-box2 {
         inset-inline: 25px 50px;
      }
   </style>
</head>

<body>
   <h2>
      CSS inset-inline property
   </h2>
   <h4>
      inset-inline: 10px (Both inline-start 
      and inline-end distances are 10px)
   </h4>
   <div class="container">
      <div class="inner inner-box1">
         This shows the inset-inline property. Observe 
         how the distance of this green area is changed 
         from the inline-start and inline-end.
      </div>
   </div>
   <h4>
      inset-inline: 25px 50px (inline-start 
      distance is 25px and inline-end distance
      is 50px)
   </h4>
   <div class="container">
      <div class="inner inner-box2">
         This shows the inset-inline property. Observe 
         how the distance of this green area is changed
         from the inline-start and inline-end.
      </div>
   </div>
</body>

</html>

使用百分比值的 Inset Inline 属性

要设置距包含块内联边缘的距离,我们可以使用百分比值(例如 10%)指定距离。最多可以给出两个值。单个值设置内联开始和内联结束距离。如果给出两个值,则第一个值设置内联开始距离,而第二个值设置内联结束距离。这在以下示例中显示。

示例

<!DOCTYPE html>
<html>

<head>
   <style>
      .container {
         border: 2px solid;
         height: 200px;
         width: 300px;
         position: relative;
      }

      .inner {
         height: 100%;
         position: absolute;
         background-color: lightgreen;
      }

      .inner-box1 {
         inset-inline: 10%;
      }

      .inner-box2 {
         inset-inline: 20% 40%;
      }
   </style>
</head>

<body>
   <h2>
      CSS inset-inline property
   </h2>
   <h4>
      inset-inline: 10% (Both inline-start 
      and inline-end distances are 10% of 
      the container)
   </h4>
   <div class="container">
      <div class="inner inner-box1">
         This shows the inset-inline property. Observe 
         how the distance of this green area is changed 
         from the inline-start and inline-end.
      </div>
   </div>
   <h4>
      inset-inline: 20% 40% (inline-start distance
      is 20% and inline-end distance is 40% of 
      the container)
   </h4>
   <div class="container">
      <div class="inner inner-box2">
         This shows the inset-inline property. Observe 
         how the distance of this green area is changed 
         from the inline-start and inline-end.
      </div>
   </div>
</body>

</html>

使用混合值的 Inset Inline 属性

要设置距包含块内联边缘的距离,我们可以使用长度和百分比值的组合(例如 10px 20%)指定距离。这在以下示例中显示。

示例

<!DOCTYPE html>
<html>

<head>
   <style>
      .container {
         border: 2px solid;
         height: 200px;
         width: 300px;
         position: relative;
      }

      .inner {
         height: 100%;
         position: absolute;
         background-color: lightgreen;
      }

      .inner-box1 {
         inset-inline: 10% 55px;
      }

      .inner-box2 {
         inset-inline: 75px 15%;
      }
   </style>
</head>

<body>
   <h2>
      CSS inset-inline property
   </h2>
   <h4>
      inset-inline: 10% 55px (inline-start distance 
      is 10% of container and inline-end distance 
      is 55px )
   </h4>
   <div class="container">
      <div class="inner inner-box1">
         This shows the inset-inline property. Observe 
         how the distance of this green area is changed 
         from the inline-start and inline-end.
      </div>
   </div>
   <h4>
      inset-inline: 75px 15% (inline-start distance 
      is 75px and inline-end distance is 15% of 
      the container)
   </h4>
   <div class="container">
      <div class="inner inner-box2">
         This shows the inset-inline property. Observe 
         how the distance of this green area is changed 
         from the inline-start and inline-end.
      </div>
   </div>
</body>

</html>

使用书写模式的 Inset Inline 属性

inset-inline 属性可以与 writing-mode 属性结合使用,该属性确定文本的方向。在水平模式下,它影响左右距离。在垂直模式下,它影响上下距离。这在以下示例中显示。

示例

<!DOCTYPE html>
<html>

<head>
    <style>
        .container {
            border: 2px solid;
            height: 300px;
            width: 300px;
            position: relative;
        }

        .inner {

            position: absolute;
            background-color: lightgreen;
            inset-inline: 30px 40px;
        }

        .inner-box1 {
            height: 100%;
            writing-mode: horizontal-lr;

        }

        .inner-box2 {
            width: 100%;
            writing-mode: vertical-rl;
        }
    </style>
</head>

<body>
    <h2>
        CSS inset-inline property
    </h2>
    <h4>
        inset-inline: 30px 40px ; writing mode: horizontal-lr
    </h4>
    <div class="container">
        <div class="inner inner-box1">
            This shows the inset-inline property. Observe 
            how the distance of this green area is changed 
            from the inline-start and inline-end.
        </div>
    </div>
    <h4>
        inset-inline: 30px 40px ; writing-mode: vertical-lr
    </h4>
    <div class="container">
        <div class="inner inner-box2">
            This shows the inset-inline property. Observe 
            how the distance of this green area is changed 
            from the inline-start and inline-end.
        </div>
    </div>
</body>

</html>

支持的浏览器

属性 Chrome Edge Firefox Safari Opera
inset-inline 87.0 87.0 63.0 14.1 73.0
css_properties_reference.htm
广告