简体   繁体   English

自定义类不覆盖其他CSS

[英]Custom Class Not Overriding Other CSS

I am by no means a CSS expert, so I probably just don't understand something simple here. 我绝不是CSS专家,所以我可能在这里不了解简单的内容。

I have a site I am maintaining. 我有一个网站要维护。 Most of the site has a dark background with white text. 该网站的大多数内容都是深色背景,带有白色文字。 I was asked to change a couple of pages to black text on white background. 我被要求将几页更改为白色背景上的黑色文本。

I created a class named .blog in the CSS, it looks like this: 我在CSS中创建了一个名为.blog的类,它看起来像这样:

.blog{
color:rgb(0,0,0);
background-color:rgb(255,255,255);
}
.blog h1,h2,h3,h4,h5,h6
 {
color:rgb(0,0,0);
}
.blog a:link,a:visited,a:hover
{
color:rgb(0,0,0);
}   

Earlier in the file is this: 该文件中的较早位置是:

body,a,.white{color:#fff;}

When I wrap a chunk of a page in the text and background change but the links and headlines remain white (and are thus invisible on the white page). 当我在文本中包裹页面的一部分时,背景会发生变化,但是链接和标题仍为白色(因此在白页上不可见)。

When I check using Firebug it shows my blog class being applied, including when I select the headline or link elements. 当我使用Firebug进行检查时,它显示了我的博客类正在被应用,包括当我选择标题或链接元素时。 Yet of course it is not. 当然不是。

Can anyone suggest a reason for this? 有人可以提出原因吗? Or perhaps where I should look for the most likely solution? 也许我应该在哪里寻找最可能的解决方案?

You have to add the class before the element to specify under what circumstances which item is being selected. 您必须在元素之前添加类,以指定在什么情况下选择了哪个项目。

Thus 从而

.blog h1,h2,h3,h4,h5,h6
 {
color:rgb(0,0,0);
}

should be 应该

.blog h1, .blog h2, .blog h3, .blog h4, .blog h5, .blog h6 {
color:rgb(0,0,0);
 }

and so on. 等等。

You can always try and add !important to the end of your class. 您可以随时尝试在班级末尾添加!important

For example: 例如:

background-color:rgb(255,255,255) !important;

This will override any element that is over-styling the background-color of your blog class for instance. 例如,这将覆盖任何样式过高的Blog类background-color的元素。 Though I do not recommend using this all of the time as you can end up causing yourself conflicting issues but it is there for cases like this. 尽管我不建议您一直使用此功能,否则您最终可能会导致冲突的问题,但是这种情况适用于此类情况。

Definitely give it a shot and see if it fixes your issue, if it does then you have another class that is overriding your styling, or your class styling is not correctly being issued where you think it is. 一定要试一试,看看它是否可以解决您的问题,如果可以,那么您有另一个类正在重写您的样式,或者您认为正确的位置没有正确发出您的类样式。

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

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