简体   繁体   English

清除指定CSS规则的div

[英]clean a div of a specified css rules

In a website, I have a header and footer that comes from another website. 在一个网站中,我有另一个网站的页眉和页脚。

Those header and footers came with javascript and add lots of CSS files (CSS files used from another website) ... and the main website too! 这些页眉和页脚是javascript附带的,并添加了许多CSS文件(从另一个网站使用的CSS文件)...以及主要网站! Those CSS are like battle themselves and the rendreing of the header and footer are like mixed styles because of mixing CSS rules from all css files... 这些CSS就像战斗自己一样,并且由于混合了所有css文件中的CSS规则,所以页眉和页脚的渲染就像混合样式一样...

How Can I remove all the CSS rules (main.css) on the two part of the main website and just apply the "headerAndFooter.css" on those two parts? 如何删除主网站两部分上的所有CSS规则(main.css),仅在这两部分上应用“ headerAndFooter.css”?

The every part havs his proper div. 每个部分都有自己应有的格。

Thanks in advance 提前致谢

You should create a new class for your headers and footers in a separate CSS file - and enter the needed styles there. 您应该在单独的CSS文件中为页眉和页脚创建一个新类-并在其中输入所需的样式。 That way, they won't conflict with the rest of your site - and you won't compromise the rest of your site's layout by modifying global CSS. 这样,它们就不会与您网站的其余部分发生冲突-并且您不会通过修改全局CSS来损害网站其余部分的布局。

Of course, without seeing any of your code, it's hard to provide a detailed answer, but in cases like this, more accurate class names are a good starting point. 当然,在看不到任何代码的情况下,很难提供详细的答案,但是在这种情况下,更准确的类名是一个很好的起点。

You can use !important at the end of the value of the property you are trying to change, if you have several rules overwriting each other. 如果您有多个相互覆盖的规则,则可以在要更改的属性值的末尾使用!important

For example: the blue color would show, not the red, because you labeled the blue as important. 例如:因为您将蓝色标记为重要,所以将显示蓝色而不显示红色。

body {
    color:red;
}

body {
    color:blue !important;
}

A better solution would be to just erase the rules that you don't need from the different css files. 更好的解决方案是从不同的css文件中删除不需要的规则。

I finally download the incoming CSS and prefix them by #header and #footer. 最后,我下载了传入的CSS,并在它们前面加上#header和#footer前缀。 Than I ahave full control of all CSS because I use it locally. 比起我拥有对所有CSS的完全控制,因为我在本地使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM