border-top
試一試
border-top: solid;
border-top: dashed red;
border-top: 1rem solid;
border-top: thick double #32a1ce;
border-top: 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-top 總是會設定它能設定的所有屬性的值,即使這些屬性沒有被明確指定。它會將未明確指定的屬性設定為其預設值。請看以下程式碼:
css
border-top-style: dotted;
border-top: thick green;
它實際上與此程式碼相同:
css
border-top-style: dotted;
border-top: none thick green;
在 border-top 之前給定的 border-top-style 值將被忽略。由於 border-top-style 的預設值是 none,因此不指定 border-style 部分會導致沒有邊框。
構成屬性
此屬性是以下 CSS 屬性的簡寫:
語法
css
border-top: 1px;
border-top: 2px dotted;
border-top: medium dashed green;
/* Global values */
border-top: inherit;
border-top: initial;
border-top: revert;
border-top: revert-layer;
border-top: unset;
簡寫屬性的三個值可以按任意順序指定,其中一個或兩個可以省略。
值
<br-width>-
請參閱
border-top-width。 <br-style>-
請參閱
border-top-style。 <color>-
請參閱
border-top-color。
正式定義
| 初始值 | 作為簡寫中的每個屬性
|
|---|---|
| 應用於 | 所有元素。也適用於 ::first-letter。 |
| 繼承性 | 否 |
| 計算值 | 作為簡寫中的每個屬性
|
| 動畫型別 | 作為簡寫中的每個屬性
|
正式語法
border-top =
<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 top side.</div>
CSS
css
div {
border-top: 4px dashed blue;
background-color: gold;
height: 100px;
width: 100px;
font-weight: bold;
text-align: center;
}
結果
規範
| 規範 |
|---|
| CSS Backgrounds and Borders Module Level 3 # 邊框簡寫 |
瀏覽器相容性
載入中…