border-bottom

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

border-bottomCSS 簡寫屬性,用於設定元素的底部邊框。它設定 border-bottom-widthborder-bottom-styleborder-bottom-color 的值。

試一試

border-bottom: solid;
border-bottom: dashed red;
border-bottom: 1rem solid;
border-bottom: thick double #32a1ce;
border-bottom: 4mm ridge rgb(211 220 50 / 0.6);
<section class="default-example" id="default-example">
  <div class="transition-all" id="example-element">
    This is a box with a border around it.
  </div>
</section>
#example-element {
  background-color: #eeeeee;
  color: darkmagenta;
  padding: 0.75em;
  width: 80%;
  height: 100px;
}

與所有簡寫屬性一樣,border-bottom 總是設定它可以設定的所有屬性的值,即使它們未被指定。它會將未指定的屬性設定為其預設值。考慮以下程式碼:

css
border-bottom-style: dotted;
border-bottom: thick green;

它實際上與此程式碼相同:

css
border-bottom-style: dotted;
border-bottom: none thick green;

border-bottom 之前給出的 border-bottom-style 的值將被忽略。由於 border-bottom-style 的預設值為 none,因此未指定 border-style 部分會導致沒有邊框。

構成屬性

此屬性是以下 CSS 屬性的簡寫:

語法

css
border-bottom: 1px;
border-bottom: 2px dotted;
border-bottom: medium dashed blue;

/* Global values */
border-bottom: inherit;
border-bottom: initial;
border-bottom: revert;
border-bottom: revert-layer;
border-bottom: unset;

簡寫屬性的三個值可以按任意順序指定,其中一個或兩個可以省略。

<br-width>

參閱 border-bottom-width

<br-style>

參閱 border-bottom-style

<color>

參閱 border-bottom-color

正式定義

初始值作為簡寫中的每個屬性
應用於所有元素。也適用於 ::first-letter
繼承性
計算值作為簡寫中的每個屬性
動畫型別作為簡寫中的每個屬性

正式語法

border-bottom = 
<line-width> ||
<line-style> ||
<color>

<line-width> =
<length [0,∞]> |
thin |
medium |
thick

<line-style> =
none |
hidden |
dotted |
dashed |
solid |
double |
groove |
ridge |
inset |
outset

示例

應用底部邊框

HTML

html
<div>This box has a border on the bottom side.</div>

CSS

css
div {
  border-bottom: 4px dashed blue;
  background-color: gold;
  height: 100px;
  width: 100px;
  font-weight: bold;
  text-align: center;
}

結果

規範

規範
CSS Backgrounds and Borders Module Level 3
# 邊框簡寫

瀏覽器相容性

另見