CSS * {margin: 0;padding: 0;} 覆盖

发布于 2024-08-31 09:39:05 字数 1697 浏览 6 评论 0原文

大家好,我需要一些帮助来弄清楚如何覆盖我的 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 中时,它会使注释堆栈错误:

 1st comment
    2nd comment
        3rd comment

我只会采取出 * {margin: 0;padding: 0;} 但页面上的其他一些内容需要它才能正确显示。所以我的问题是,如何覆盖页面的评论部分的 {margin: 0;padding: 0;} ?

谢谢! :o)

大卫

更新: 出色地。仍然无法正确获取。去掉整个网站的边距:0px - 它使网站看起来很糟糕。如果我必须向页面的每个元素添加 margin: 0px 以使其看起来像带有 * 的那样,那就不好了。我仍然只需要一些东西来绕过 .postcomments 部分,仅此而已。

Hey all, i am in need of some help with figuring out how to override the "* {margin: 0;padding: 0;}" in my css.

The reason why is that i have this 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;}

and it displays just fine WITHOUT the * {margin: 0;padding: 0;}:

 1st comment
 2nd comment
 3rd comment

However, when i add that to the CSS, it makes the comments stack wrong:

 1st comment
    2nd comment
        3rd comment

I would just take out the * {margin: 0;padding: 0;} but some other things on the page needs that in order for that to be displayed correctly. So my question is, how can i override the {margin: 0;padding: 0;} for just that postcomments part of the page?

Thanks! :o)

David

UPDATE:
Well. still can not get it correctly. After taking out the margin: 0px for the whole site- it makes the site look terrible. And if i have to add margin: 0px to every element to the page to make it look like it would with the * then thats not good. I still just need something to bypass it for the .postcomments part and thats it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

跨年 2024-09-07 09:39:05

你尝试过 !important 吗?

.postcomments {
   margin: 15px  !important;
   padding: 15px !important;
}

我使用的是 15px,但你可以使用任何适合你的值

Did you try it with !important?

.postcomments {
   margin: 15px  !important;
   padding: 15px !important;
}

i am using 15px, but you can use whatever value works for you

半岛未凉 2024-09-07 09:39:05

也许使用一个可用的reset.css(eric meyer 例如)脚本。然后观察如何构建无序列表。如果有嵌套的 ul,通常每个 ul 都会有一个 margin-left

Maybe use one reset.css (eric meyer e.g.) scripts available. then watch how you build the unordered lists. if there are nested ul you would normally get a margin-left for each ul

韵柒 2024-09-07 09:39:05

.postcomments 应该覆盖 *,因为类更具体。

.postcomments should override *, since a class is more specific.

望她远 2024-09-07 09:39:05

您需要提供比其他答案包含的内容更具体的内容,

尝试将标签放在类或父标签的前面,

div.postcomments {
span.postcomments {

或者如果这不是一个选项,您可以随时求助于

* .postcomments {

You'll need to provide more specificity then what the other answers contain

try putting the tag infront of the class, or a parent tag

div.postcomments {
span.postcomments {

or if that's not an option, you can always resort to

* .postcomments {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文