关于css里面的一个问题_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 08:46:44
Original
1102 people have browsed it

为什么下面的代码出来之后我加了class=“bg”的模块不变成绿色的呢?不是就近原则吗?刚开始学,还请高手解答
css代码:
.text div{
margin-top:100px;
width:100px;
height:100px;
background-color:pink;
}

.bg{
background-color:green;
}
html代码:






回复讨论(解决方案)

这是CSS选择器的优先级问题
http://www.cnblogs.com/iloveyoucc/archive/2012/09/06/2673003.html

我在.bg前面再加一个.text就变成绿色了   谢谢

http://www.cnblogs.com/wangfupeng1988/p/4285251.html

这篇blog写得还可以,去看看吧,

.text div  的优先级是 10 + 1 = 11

.bg  的优先级是 10

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!