border-top
CSS属性border-top是属性border-top-color
,border-top-style
,和border-top-width
的三者的缩写。这些属性都是在描述一个元素的上方的边框border
。
border-top: solid; border-top: dashed red; border-top: 1rem solid; border-top: thick double #32a1ce; border-top: 4mm ridge rgb(170, 50, 220, .6);
与所有缩写属性(shorthand properties)一样,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
。
示例
border-top: 1px; border-top: 2px dotted; border-top: medium dashed green;
浏览器支持
![]() | ![]() | ![]() | ![]() | ![]() |
浏览器都支持border-top |
语法
border-top :border-width| border-top-style| border-top-color
取值:
- border-width:设置或检索对象边框宽度。取值<length>| thin| medium| thick。参见
border-width
。 - border-top-style:设置或检索对象边框样式。取值 none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset。参见
border-top-style
。 - border-top-color:设置或检索对象边框颜色。。参见
border-top-color
。
初始值 |
|
适用于 | 所有元素,::first-letter |
继承性 | 无 |
动画性 | 否 |
计算值 |
|
实例
<div> this box has a border on the top side. </div> div { border-top: 4px dashed blue; background-color: gold; height: 100px; width: 100px; font-weight: bold; text-align: center; }