CSS:双重声明有什么作用?
我正在为 WordPress 构建一个自定义主题,并在默认的 2010 style.css 文件中看到了这一点:
#wrapper {
margin: 0 auto;
width: 940px;
}
#wrapper {
background: pink;
margin-top: 20px;
padding: 0 20px;
}
现在这是默认代码(pink
除外)。当我尝试折叠它时,这似乎合乎逻辑,但它却产生了很大的不同。
我不明白的是为什么你要像这样声明同一个元素两次?我以前从未见过...
WR!
i'm building a custom theme for wordpress and saw this in the default 2010 style.css file:
#wrapper {
margin: 0 auto;
width: 940px;
}
#wrapper {
background: pink;
margin-top: 20px;
padding: 0 20px;
}
now this is the default code (except the pink
). when i try and collapse it, which seems logical, it makes quite a difference.
what i can't figure out is WHY you'd declare the same element twice like that? i've never seen that before...
WR!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您想要在多个元素上应用共享属性时,它被证明是有用的。另一个有用的应用程序是添加来自多个源的样式表
示例:
第二个示例:来自多个源的 CSS:
当两个属性具有相同的特异性时,将应用最后声明的属性。
It proves useful when you want to apply shared properties at multiple elements. Another useful application is adding stylesheets from multiple sources
Example:
Second example: CSS from multiple sources:
When two properties have the same specificity, the lastly declared property will be applied.
它只是覆盖之前声明的属性。
wrapper
现在将具有margin:20px auto 0 auto
(右上左下)。It just overrides previously declared properties.
wrapper
will now havemargin:20px auto 0 auto
(Top Right Bottom Left).