CSS
背景和边框 | Backgrounds & Borders

边框属性 | border-top

border-top

CSS属性 border-top是属性border-top-color,border-top-style, 和border-top-width 的三者的缩写。这些属性都是在描述一个元素的上方的边框border

border-top: 1px; border-top: 2px dotted; border-top: medium dashed green;

和CSS所有的缩写属性一样,border-top总是会设置该缩写属性所包含的全部属性值,即使开发者并没有一一指定这些值。CSS缩写属性会给没有被定义的属性一个默认的属性值。那就意味着下面这个例子......

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的最终结果就是没有边框。

初始值as each of the properties of the shorthand: border-top-width: medium border-top-style: none border-top-color: currentcolor
适用元素all elements. It also applies to ::first-letter.
是否是继承属性no
适用媒体visual
计算值as each of the properties of the shorthand: border-top-width: the absolute length or 0 if border-top-style is none or hidden border-top-style: as specified border-top-color: computed color
Animation typeas each of the properties of the shorthand: border-top-color: a color border-top-style: discrete border-top-width: a length
正规顺序order of appearance in the formal grammar of the values

  • border-top-widthmedium

  • border-top-stylenone

  • border-top-color:currentcolor

Applies to all elements. It also applies to [`::first-letter`](::first-letter). [Inherited](inheritance) no Media visual [Computed value](computed_value) as each of the properties of the shorthand:

  • border-top-width:绝对长度或0如果border-top-stylenonehidden

  • border-top-style:具体规定

  • border-top-color:计算颜色

Animation type as each of the properties of the shorthand:

  • border-top-color:颜色

  • border-top-style:离散

  • border-top-width:长度

Canonical order order of appearance in the formal grammar of the values

语法

这三种属性值的缩写需要按照顺序定义数值,也可以省略其中的一个或者两个。

<br-width> 请参阅border-top-width.<br-style> 请参阅border-top-style.<color>请参阅border-top-color.

正式语法

<br-width> || <br-style> || <color>where <br-width> = <length> | thin | medium | thick <br-style> = none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset <color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color> where <rgb()> = rgb( [ [ <percentage>{3} | <number>{3} ] [ / <alpha-value> ]? ] | [ [ <percentage>#{3} | <number>#{3} ] , <alpha-value>? ] ) <rgba()> = rgba( [ [ <percentage>{3} | <number>{3} ] [ / <alpha-value> ]? ] | [ [ <percentage>#{3} | <number>#{3} ] , <alpha-value>? ] ) <hsl()> = hsl( [ <hue> <percentage> <percentage> [ / <alpha-value> ]? ] | [ <hue>, <percentage>, <percentage>, <alpha-value>? ] ) <hsla()> = hsla( [ <hue> <percentage> <percentage> [ / <alpha-value> ]? ] | [ <hue>, <percentage>, <percentage>, <alpha-value>? ] ) where <alpha-value> = <number> | <percentage> <hue> = <number> | <angle>

示例

<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; }

规范

SpecificationStatusComment
CSS Backgrounds and Borders Module Level 3The definition of 'border-top' in that specification.Candidate RecommendationNo direct changes, though the modification of values for the border-top-color do apply to it.
CSS Level 2 (Revision 1)The definition of 'border-top' in that specification.RecommendationNo significant changes.
CSS Level 1The definition of 'border-top' in that specification.RecommendationInitial definition.

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support1.0(Yes)1.0 (1.7 or earlier)43.51.0 (85)

FeatureAndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support1.0(Yes)1.0 (1.0)(Yes)(Yes)(Yes)