border-top
border-top
は一括指定の CSS のプロパティで、要素の上側の境界のプロパティをすべて設定します。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 https://github.com/mdn/interactive-examples をクローンしてプルリクエストを送信してください。
他の一括指定プロパティと同様に、 border-top
は、一部の値が指定されていなくても、設定可能なプロパティをすべて設定します。指定されていないプロパティは既定値が設定されます。つまり・・・
border-top-style: dotted;
border-top: thick green;
・・・は、実際には以下と同じです・・・
border-top-style: dotted;
border-top: none thick green;
・・・そして、 border-top
の前で設定された border-top-style
の値は無視されます。 border-top-style
の既定値は none
なので、 border-style
の部分の設定は境界線なしとなります。
構成要素のプロパティ
このプロパティは以下の CSS プロパティの一括指定です。
構文
border-top: 1px;
border-top: 2px dotted;
border-top: medium dashed green;
一括指定プロパティの3つの値は任意の順序で指定可能で、また、1つまたは2つの値を省略することができます。
値
<br-width>
border-top-width
を参照してください。<br-style>
border-top-style
を参照してください。<color>
border-top-color
を参照してください。
公式定義
初期値 | 一括指定の次の各プロパティとして
|
---|---|
適用対象 | すべての要素。 ::first-letter にも適用されます。 |
継承 | なし |
計算値 | 一括指定の次の各プロパティとして
|
アニメーションの種類 | 一括指定の次の各プロパティとして |
形式文法
<line-width> || <line-style> || <color>ここで
<line-width> = <length> | thin | medium | thick
<line-style> = none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset
<color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color>ここで
<rgb()> = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )
<rgba()> = rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )
<hsl()> = hsl( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsl( <hue>, <percentage>, <percentage>, <alpha-value>? )
<hsla()> = hsla( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsla( <hue>, <percentage>, <percentage>, <alpha-value>? )ここで
<alpha-value> = <number> | <percentage>
<hue> = <number> | <angle>
例
上側の境界の適用
HTML
<div>
このボックスには上側に境界線があります。
</div>
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 border-top の定義 |
勧告候補 | 直接的な変更はないが、 border-top-color に適用される値が変更された。 |
CSS Level 2 (Revision 1) border-top の定義 |
勧告 | 有意な変更点なし。 |
CSS Level 1 border-top の定義 |
勧告 | 初回定義 |
ブラウザーの互換性
BCD tables only load in the browser