如何覆盖CSS类中的优先级?
- Home
- Option 1
- Option 2
And I apply the styles with this classes
我将这些类应用于这些类
#contentheader .cat {
border-top:3px solid #ccc;
background-color:#eee;
overflow:hidden;
}
#contentheader .cat li a {
color:#999;
font-weight:700;
text-decoration:none;
font-size:13px;
display:block;
border-right:1px solid #fff;
float:left;
padding:10px;
}
#contentheader .cat li a:hover {
background-color:#E9E9E9;
}
The problem is that I need the first <li>
(Home) to be different, maybe making the text in other color, or maybe making the font wider. I try assigning a class directly to the <li>
or the <a>
tags, but it doesn't works, it always take the styles in the #contentheader .cat li a
class. What is the best way to do this? Thanks
问题是我需要第一个
或标签,但它不起作用,它总是将#contentheader .cat li中的样式作为一个类。做这个的最好方式是什么?谢谢
2 个解决方案
#1
You need to increase the specificity of that selector to have it override a rule with a lower selector specificity.
您需要增加该选择器的特异性,以使其覆盖具有较低选择器特异性的规则。
So if you assign the class to the li
element, use #contentheader .cat li
.class
a
, for the a
element, use #contentheader .cat li a
.class
.
因此,如果将类分配给li元素,请使用#contentheader .cat li.class a,对于a元素,请使用#contentheader .cat li a.class。
更多相关文章
- 单选按钮和多选按钮的样式设置
- 工作中遇到的几个CSS样式表的问题
- php 把驼峰样式的字符串转换成下划线样式的字符串
- 来自php表单的样式电子邮件
- 当页面上有多个按钮时,按钮样式在页面加载上有厚的边框
- 为什么通过JavaScript更改样式会受到CSS过渡的影响
- 如何在execCommand formatBlock 'p'标签中添加类或id或CSS样式?
- arcgis api for js入门开发系列十 自定义Navigation控件样式风格
- Javascript没有返回样式属性[重复]