border-top-color
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
border-top-color
是一種 CSS 屬性,用來設定元件上側邊框的顏色。也可由含括此屬性功能的簡寫屬性 border-color
或 border-top
設定該屬性值。
嘗試一下
border-top-color: red;
border-top-color: #32a1ce;
border-top-color: rgb(170, 50, 220, 0.6);
border-top-color: hsl(60, 90%, 50%, 0.8);
border-top-color: transparent;
<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: #eee;
color: #000;
border: 0.75em solid;
padding: 0.75em;
width: 80%;
height: 100px;
}
語法
css
/* <color> values */
border-top-color: red;
border-top-color: #ffbb00;
border-top-color: rgb(255, 0, 0);
border-top-color: hsla(100%, 50%, 25%, 0.75);
border-top-color: currentcolor;
border-top-color: transparent;
/* Global values */
border-top-color: inherit;
border-top-color: initial;
border-top-color: revert;
border-top-color: revert-layer;
border-top-color: unset;
border-top-color
只能宣告一個屬性值。
屬性值
<color>
-
定義上側邊框色彩。
Formal definition 標準定義
預設值 | currentcolor |
---|---|
Applies to | all elements. It also applies to ::first-letter . |
繼承與否 | no |
Computed value | computed color |
Animation type | a color |
Formal syntax 語法規則
範例
簡易邊框範例
HTML
html
<div class="mybox">
<p>
這是一個帶有框線的方框。 請注意某側框線顏色已設為
<span class="redtext">紅色</span>。
</p>
</div>
CSS
css
.mybox {
border: solid 0.3em gold;
border-top-color: red;
width: auto;
}
.redtext {
color: red;
}
成果
規範
Specification |
---|
CSS Backgrounds and Borders Module Level 3 # border-color |
瀏覽器相容性
參見
- 與框線相關的簡寫屬性:
border
、border-top
、border-color
。 - 與顏色相關的其他框線屬性:
border-right-color
、border-bottom-color
、border-left-color
。 - 與同側框線相關的其他屬性:
border-top-style
、border-top-width
。