首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于包含某些重复类的第二个CSS文件而清除CSS样式

问由于包含某些重复类的第二个CSS文件而清除CSS样式
EN

Stack Overflow用户
提问于 2012-08-31 06:54:31
回答 1查看 1.3K关注 0票数 1

有没有一种全局的方法来清除div中的CSS样式,因为样式名称重复?我们正在合并内容,并试图通过使用多个样式表来最小化工作。这是我一直在做的一个测试:http://jsfiddle.net/Codewalker/yU2sW/7/。但是,由于它是JSFiddle,所以我没有引用两个外部样式表,而是在CSS窗口中将它们组合在一起。注意secondary_container div是如何从另一个容器继承蓝色文本的。我还粘贴了以下代码:

代码语言:javascript
复制
<div class="container">
<h1>This is in an h1 tag.</h1>
<p>This is at the very top, outside the secondary_container stuff. All kinds of content     can go down here. All of this is within a paragraph tag. I'll write one more sentence then     copy all this over again. Sound good? Wait that's two more sentences. Actually four. Oh well. So much for that. Here goes a little copying and pasting. All kinds of content can go down here. All of this is within a paragraph tag. I'll write one more sentence then copy all this over again. Sound good? Wait that's two more sentences. Actually four. Oh well. So much for that. Here goes a little copying and pasting.</p>

<div id="secondary_container">
<div class="container">

<p>This is within the container div that's within the secondery_container div. All kinds of content can go down here. All of this is within a paragraph tag. I'll write one more sentence then copy all this over again. Sound good? Wait that's two more sentences. Actually four. Oh well. So much for that. Here goes a little copying and pasting. All kinds of content can go down here. All of this is within a paragraph tag. I'll write one more sentence then copy all this over again. Sound good? Wait that's two more sentences. Actually four. Oh well. So much for that. Here goes a little copying and pasting.</p>
</div>
</div>
</div>

下面是CSS,它实际上是两个独立的外部样式表:

代码语言:javascript
复制
/* BEGINNING OF FIRST CSS FILE styler.css */

.container {
background-color: #00FF00;
height: auto;
width:960px;
margin: 0 auto;
line-height: 20px;
}

h1 { font-family:Arial, Helvetica, sans-serif; font-size:14px; color: #F00; text-transform:uppercase; }
p { font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#00F; 

}

/* BEGINNING OF SECOND CSS FILE secondary_container.css 
*/

#secondary_container .container h1 { font-family:Georgia, "Times New Roman", Times, serif; color: #0F0; }
#secondary_container .container p { font-style:italic; line-height:14px;}
EN

回答 1

Stack Overflow用户

发布于 2012-08-31 07:09:04

您似乎有一点名称空间的冲突,理想情况下,如果经过深思熟虑,您不应该出现这种情况。或者更精确,或者更确切地说,不那么模糊。例如,您可以将元素包装在单独的div中,或者使用css链接。

CSS有很多有用的代码片段,你可以在遇到麻烦时使用,比如>,当它像div > p.myClass一样使用时,只适用于带有myClass类的p,它是div的子类。你甚至可以通过使用:first-child选择器来使它更具体,这意味着它将只应用于第一个p标签,带有.myClass的类,这是div. div > p.myClass:first-child的子类。

真的,如果类不需要样式属性,为什么还要使用它呢?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12206749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档