border-width

CSS border-width Property

CSS border-width property sets the widths of all four sides of an element’s border. It is a shorthand property which specifies:

  • border-top-width, which defines the width of an element’s top border.

  • border-left-width, which defines the width of an element’s left border.

  • border-right-width, which defines the width of an element’s right border.

  • border-bottom-width, which defines the width of an element’s bottom border.

This property has four values. When one value is used, the border-width value will apply to all four sides of the element (i.e. top, right, bottom, left). If two values are used, the first value will apply to the top and bottom of the element. The second value will apply to the left and right sides of the element. If three values are used, the first value will apply to the top of the element. The second value will apply to the right and left sides of the element. The third value will apply to the bottom of the element. When four values are used, the first value will apply to the top of the element. The second value will apply to the right side of the element. The third value will apply to the bottom of the element. The fourth value will apply to the left side of the element.

Firstly you should define border-style property then the border-width property. An element must have borders before you can set the width.

类目类目
Initial Valuemedium
InheritedNo
AnimatableYes. The width of the border is animatable.
VersionCSS1
JavaScript Syntaxobject.style.borderWidth = “1px 5px”;

Syntax

Syntax

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

Example of the border-width property:

<!DOCTYPE html>
<html>
  <head>
    <style>
      p {
        border-style: solid;
        border-width: 1px;
        padding: 5px;
      }
    </style>
  </head>
  <body>
    <p>This paragraph's border is selected as 1px.</p>
  </body>
</html>

Example of the border-width property with three values:

<!DOCTYPE html>
<html>
  <head>
    <style>
      p {
        color: #666;
        padding: 5px;
        border-style: solid;
      }
      .thin {
        border-width: 1px;
      }
      .medium {
        border-width: medium;
      }
      .thick {
        border-width: 10px;
      }
    </style>
  </head>
  <body>
    <p class="thin">This paragraph's border is selected as 1px.</p>
    <p class="medium">This paragraph's border is selected as medium.</p>
    <p class="thick">This paragraph's border is selected as 10px.</p>
  </body>
</html>

Result

Values

Values

ValueDescriptionPlay it
mediumDefines a medium border. This is default value.Play it »
thinDefines a thin border.Play it »
thickDefines a thick border.Play it »
lengthDefines the thickness of border.Play it »
initialSets the property to its default value.Play it »
inheritInherits the property from its parent element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部