我们可以缩短:
border-top:1px solid black;
border-left:2px solid red;
border-bottom:3px solid green;
border-right:4px solid blue;
类似于:
border:1px solid black 2px solid red 3px solid green 4px solid blue;
N.B:我已经这样知道了:
border-width:1px 2px 3px 4px;
border-style:solid;
border-color:black red green blue;
答案 0 :(得分:11)
不,你不能比你提供的例子更短。
与速记'边距'和'填充'属性不同,'边框' 属性不能在四个边框上设置不同的值。为此, 必须使用一个或多个其他边框属性。
谢谢@Rocket
如果您使用预处理器(如SCSS),您可以尝试使用mixin,但我几乎不相信这是您想要的:
@mixin border_shorthand(
$top_width, $top_color, $top_style,
$left_width, $left_color, $left_style,
$bottom_width, $bottom_color, $bottom_style,
$right_width, $right_color, $right_style) {
border-top: $top_width $top_color $top_style;
border-left: $left_width $left_color $left_style;
border-bottom: $bottom_width $bottom_color $bottom_style;
border-right: $right_width $right_color $right_style;
}
.element {
@include border_shorthand(1px, black, solid, 2px, red, solid, 3px, green, solid, 4px, blue, solid);
}
哪个输出:
.element {
border-top: 1px black solid;
border-left: 2px red solid;
border-bottom: 3px green solid;
border-right: 4px blue solid; }