border-top-width属性用于设置一个元素的顶部边框的宽度。
一个元素顶部的边框宽度可以使用<length>值来明确指定,也可以使用三个预定义的关键字来指定:thin、medium和thick。
官方语法
border-top-width: <length> | thin | medium | thick
参数:
<length>:指定顶部边框的宽度,不允许为负值。thin:关键字,预定义顶部边框宽度。medium:关键字,预定义顶部边框宽度。thick:关键字,预定义顶部边框宽度。
border-top-width属性的初始值为medium。
注意:border-top-width属性的初始值为medium,但是元素的border属性的初始值为none,其宽度为0。
border-top-width属性可以使用关键字inherit从它的父元素中继承顶部边框的宽度。
下面是border-top-width属性取值的示例代码:
/* 可以是任何 <length> 值 */
border-top-width: 10em;
border-top-width: 3vmax;
border-top-width: 6px;
/* 可以是预定义关键字 */
border-top-width: thin;
border-top-width: medium;
border-top-width: thick;
border-top-width: inherit;
示例代码
下面的代码将元素的顶部边框设置为10像素的红色实线。
.element {
border-right-style: solid;
border-top-width: 10px;
border-right-color: red;
}
在线演示
顶部边宽度为30像素蓝色实线
顶部边宽度为关键字:thin
顶部边宽度为关键字:medium
顶部边宽度为关键字:thick
浏览器支持
所有的现代浏览器都支持border-top-width属性,包括Chrome,Firefox,Safari,Opera,IE 以及 Android 和 iOS。