微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

* CSS规则如何比类或ID样式规则更具体?

我正在使用*选择器来指示除非我另行指定,否则网站上字体的颜色应设置为某个值.
*{

font-family:"Verdana";
color: #04468e;
}

到现在为止还挺好.问题在于,这是最常规的规则,它应该很容易被覆盖,例如

#profileMessageBoxHeader
{
background:url('images/profileMessageHeaderGradient.png') repeat-x #208ff6;
height:178px;
border-radius:10px 10px 0px 0px;
color:#fff; 
}

所以下面的代码……

<div id="profileMessageBox">
    <div id="profileMessageBoxHeader">
        <
        <p>Please fill out the form and click submit.  Your entered profile data will be provided to the tutor,to allow them to contact you.</p>
    </div>
</div>

应该产生白色文字.但是,出于某种原因,极其通用的*规则会覆盖更具体的ID规则.为什么?

解决方法

*是一个通用选择器,并覆盖#profileMessageBoxHeader上的设置.它与手动设置BODY,H1,P,TABLE,TR,TD,TH,PRE,UL,LI,ETC相同.有关它的更多信息以及如何规避继承,Eric Meyer has a good article.

应用以下内容,它应该工作:

#profileMessageBoxHeader p
{
    color: #FFF;
}

样品:http://jsfiddle.net/x7AnM/

原文地址:https://www.jb51.cc/css/215048.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。