【发布时间】:2010-05-04 14:01:45
【问题描述】:
大家好,我需要一些帮助来弄清楚如何覆盖我的 CSS 中的“* {margin: 0;padding: 0;}”。
原因是我有这个css:
.postcomments { width: 547px; padding: 5px 5px 5px 5px; margin: 0 0 5px 0;}
.postcomments a { text-decoration: underline;}
.postcomments ul { margin: 0; padding: 0; list-style-type: none;}
.postcomments ul li { width: 547px; margin: 0 0 5px 0; padding: 0; list-style-type: none;}
.postcomments .right { color: #474747; font-size: 11px; background: #fff url('http://www.nextbowluser.com/img/ucBG.gif') no-repeat top left; line-height: 17px; padding: 5px 0 0 0; width: 430px; position: relative; float: right; min-height: 50px;}
.postcomments .right .bottom { padding: 0 5px 15px 5px; background: #fff url('http://www.nextbowluser.com/img/ucBG.gif') no-repeat bottom right; min-height: 50px;}
.postcomments .arrow { left: -15px; top: 20px; position: absolute;}
.avatar { border: none !important;}
.postcomments .left {float: left; margin: 0 7px 0 0;}
.postcomments .gravatar { background: #fff; width: 80px; height: 60px; margin: 0 0px 0 0; padding: 3px;}
.postcomments .name { font-size: 11px; margin: 2px 0 0 0; color: #000;}
.avatar { border: none !important;}
它显示得很好,没有 * {margin: 0;padding: 0;}:
1st comment
2nd comment
3rd comment
但是,当我将它添加到 CSS 中时,它会使 cmets 堆栈错误:
1st comment
2nd comment
3rd comment
我只想取出 * {margin: 0;padding: 0;} 但页面上的其他一些内容需要它才能正确显示。所以我的问题是,我怎样才能为页面的 postcmets 部分覆盖 {margin: 0;padding: 0;}?
谢谢! :o)
大卫
更新: 出色地。仍然无法正确获取。取出整个站点的边距后:0px - 这使站点看起来很糟糕。如果我必须为页面的每个元素添加 margin: 0px 以使其看起来像带有 * 的那样,那就不好了。对于 .postcmets 部分,我仍然需要一些东西来绕过它,仅此而已。
【问题讨论】:
-
别这样。给所有块元素你自己的边距/填充。
-
你的 HTML 结构是什么样的? cmets 以任何一种方式缩进似乎很奇怪。
-
Balus C 是对的;不要那样做。但是,我的直觉告诉我有一些锚元素 (
<a>) 您没有更改其边距填充。您还应该放弃使用!important并查看 CSS 特异性 - w3.org/TR/CSS2/cascade.html#specificity