CSS - border-inline-width 属性



CSS 的 border-inline-width 属性确定元素的逻辑内联边框宽度,然后根据元素的书写模式、方向性和文本方向转换为物理边框宽度。

语法

border-inline-width: medium | thin | thick | length | initial | inherit;  

属性值

描述
medium 指定中等边框宽度。默认值。
thin 指定细边框。
thick 指定粗边框。
length 厚度可以以值的格式给出。
initial 将属性设置为其默认值。
inherit 从父元素继承该属性。

CSS 内联边框宽度属性示例

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

使用 medium 值的内联边框宽度属性

要将中等宽度设置为内联边框,可以使用 medium 值。在以下示例中,border-inline-width 属性使用了 medium 值。

示例

    
<!DOCTYPE html>
<html>

<head>
   <style>
      .container {
         display: block;
         align-items: center;
         justify-content: center;
      }

      .borders {
         border: 1px solid #e74c3c;
         padding: 10px;
         text-align: center;
      }

      .border1 {
         border-inline-width: 1px;
      }

      .border2 {
         border-inline-width: medium;
      }
   </style>
</head>

<body>
   <h2>
      CSS border-inline-width property
   </h2>
   <div class="container">
      <p class="borders border1">
         This border has same width all sides.
      </p>
      <p class="borders border2">
         This border has a 'medium' 
         border-inline-width.
      </p>
   </div>
</body>

</html>

使用 thin 值的内联边框宽度属性

要将小宽度设置为内联边框,可以使用 thin 值。在以下示例中,border-inline-width 属性使用了 thin 值。

示例

    
<!DOCTYPE html>
<html>

<head>
   <style>
      .container {
         display: block;
         align-items: center;
         justify-content: center;
      }

      .borders {
         border: 5px solid #e74c3c;
         padding: 10px;
         text-align: center;
      }

      .border1 {
         border-inline-width: 5px;
      }

      .border2 {
         border-inline-width: thin;
      }
   </style>
</head>

<body>
   <h2>
      CSS border-inline-width property
   </h2>
   <div class="container">
      <p class="borders border1">
         This border has same width all sides.
      </p>
      <p class="borders border2">
         This border has a 'thin' 
         border-inline-width.
      </p>
   </div>
</body>

</html>

使用 thick 值的内联边框宽度属性

要将粗宽度设置为内联边框,可以使用 thick 值。在以下示例中,border-inline-width 属性使用了 thick 值。

示例

    
<!DOCTYPE html>
<html>

<head>
   <style>
      .container {
         display: block;
         align-items: center;
         justify-content: center;
      }

      .borders {
         border: 2px solid #e74c3c;
         padding: 10px;
         text-align: center;
      }

      .border1 {
         border-inline-width: 2px;
      }

      .border2 {
         border-inline-width: thick;
      }
   </style>
</head>

<body>
   <h2>
      CSS border-inline-width property
   </h2>
   <div class="container">
      <p class="borders border1">
         This border has same width all sides.
      </p>
      <p class="borders border2">
         This border has a 'thick' 
         border-inline-width.
      </p>
   </div>
</body>

</html>

使用长度值的内联边框宽度属性

要设置内联边框的宽度,可以使用长度值(例如 10px、15px 等)指定宽度。在以下示例中,border-inline-width 属性使用了长度值。

示例

    
<!DOCTYPE html>
<html>

<head>
   <style>
      .container {
         display: block;
         align-items: center;
         justify-content: center;
      }

      .borders {
         border: 2px solid #e74c3c;
         padding: 10px;
         text-align: center;
      }

      .border1 {
         border-inline-width: 10px;
      }

      .border2 {
         border-inline-width: 20px;
      }

      .border3 {
         border-inline-width: 50px;
      }
   </style>
</head>

<body>
   <h2>
      CSS border-inline-width property
   </h2>
   <div class="container">
      <p class="borders border1">
         This border has 10px border-inline-width.
      </p>
      <p class="borders border2">
         This border has 20px border-inline-width.
      </p>
      <p class="borders border3">
         This border has 50px border-inline-width.
      </p>
   </div>
</body>

</html>

使用多个值的内联边框宽度属性

border-inline-width 属性可以采用多个值。如果给定单个值,则 inline-startinline-end 边框具有相同的宽度值。如果给定两个值,则第一个值应用于 inline-start 边框,第二个值应用于 inline-end 边框。这些在以下示例中显示。

示例

<!DOCTYPE html>
<html>

<head>
    <style>
        .container {
            display: block;
            align-items: center;
            justify-content: center;
        }

        .borders {
            border: 2px solid grey;
            padding: 10px;
            text-align: center;
        }

        .border1 {
            border-inline-width: 8px;
        }

        .border2 {
            border-inline-width: 10px 25px;
        }

        .border3 {
            border-inline-width: thin thick;
        }
    </style>
</head>

<body>
    <h2>
        CSS border-inline-width property
    </h2>
    <div class="container">
        <p class="borders border1">
            This border has 8px 
            border-inline-width - single value.
        </p>
        <p class="borders border2">
            This border has 10px and 
            25px border-inline-width - multiple values.
        </p>
        <p class="borders border3">
            This border has 'thin' and 
            'thick' border-inline-width - multiple values.
        </p>
    </div>
</body>

</html> 

使用书写模式的内联边框宽度属性

border-inline-width 属性受书写模式的影响。在垂直书写模式下,它会影响 inline-startinline-end 边框(顶部和底部)的宽度,而在水平书写模式下,它会影响相同的边框(左侧和右侧)的宽度。这些在以下示例中显示。

示例

    
<!DOCTYPE html>
<html>

<head>
   <style>
      .container {
         display: block;
         align-items: center;
         justify-content: center;
      }

      .borders {
         border: 1px solid #e74c3c;
         padding: 10px;
         text-align: center;
      }

      .border1 {
         border-inline-width: 10px 25px;
         writing-mode: horizontal-tb;
      }

      .border2 {
         border-inline-width: 10px 25px;
         writing-mode: vertical-lr;
      }
   </style>
</head>

<body>
   <h2>
      CSS border-inline-width property
   </h2>
   <div class="container">
      <p class="borders border1">
         This border has 10px and 25px border-inline-width
         with horizontal writing mode.
      </p>
      <p class="borders border2">
         This border has 10px and 25px border-inline-width
         with vertical writing mode.
      </p>
   </div>
</body>

</html>

使用方向的内联边框宽度属性

border-inline-width 属性会根据文本方向发生变化。在从右到左 (RTL) 方向中,它会影响从右到左方向的 inline-startinline-end 边框,而在从左到右 (LTR) 方向中,它会在相反的方向(从左到右)执行相同的操作。这在以下示例中显示。

示例

    
<!DOCTYPE html>
<html>

<head>
   <style>
      .container {
         display: block;
         align-items: center;
         justify-content: center;
      }

      .borders {
         border: 1px solid #e74c3c;
         padding: 10px;
         text-align: center;
      }

      .border1 {
         border-inline-width: 10px 25px;
         direction: rtl;
      }

      .border2 {
         border-inline-width: 10px 25px;
         direction: ltr;
      }
   </style>
</head>

<body>
   <h2>
      CSS border-inline-width property
   </h2>
   <div class="container">
      <p class="borders border1">
         This border has 10px and 25px border-inline-width
         with (right-to-left) direction.
      </p>
      <p class="borders border2">
         This border has 10px and 25px border-inline-width
         with (left-to-right) direction.
      </p>
   </div>
</body>

</html>

支持的浏览器

属性 Chrome Edge Firefox Safari Opera
border-inline-width 87.0 87.0 66.0 14.1 73.0
css_properties_reference.htm
广告