3

我一直想问这个问题,例如在覆盖默认hr外观时,这样做是否更好:

hr {
  border: none;
  border-top: 1px dashed #000;
}

或这个:

hr {
  border-top: 1px dashed #000;
  border-left: none;
  border-right: none;
  border-bottom: none;
}
4

2 回答 2

3

你的第一个例子:

hr {
  border: none;
  border-top: 1px dashed #000;
}

相当于:

hr {
  border-top: none;
  border-right: none;
  border-bottom: none;
  border-left: none;
  border-top: 1px dashed #000;
}

http://www.w3.org/TR/CSS2/box.html#propdef-border

因此,可以说您对同一属性应用了两次规则,但这不是值得关注的事情。

于 2013-06-21T07:12:25.943 回答
2

两个例子都没有错,但是第一个例子的代码更少,所以我更喜欢第一个。

于 2013-06-21T06:57:53.320 回答