有没有一种方法可以像超级速记样式一样在CSS中组合border-top,border-right,border-left,border-bottom。
例如:
border: (1px solid #ff0) (2px dashed #f0F) (3px dotted #F00) (5px solid #09f);
Answers:
不,您不能在一个语句中全部设置它们。
通常,您至少需要三个属性:
border-color: red green white blue;
border-style: solid dashed dotted solid;
border-width: 1px 2px 3px 4px;
但是,那将非常混乱。使用以下四个方法将更易于阅读和维护:
border-top: 1px solid #ff0;
border-right: 2px dashed #f0F;
border-bottom: 3px dotted #f00;
border-left: 5px solid #09f;
您的案例是一个极端的案例,但是这里是针对其他案例的一种解决方案,它适合一种更常见的情况,即要样式少于4个完全相同的边框。
border: 1px dashed red; border-width: 1px 1px 0 1px;
比它短一点,也许比
border-top: 1px dashed red; border-right: 1px dashed red; border-left: 1px dashed red;
要么
border-color: red; border-style: dashed; border-width: 1px 1px 0 1px;
不,例如,如果您有div {border-top:2px solid red; 右边框:2px纯红色;边框底部:2px稳定红色;左边框:2px纯红色;}具有相同的属性,那么您可以在一行中设置它们
div{border:2px solid red;}