Home  >  Article  >  Web Front-end  >  CSS选择器优先级问题_html/css_WEB-ITnose

CSS选择器优先级问题_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:08:231047browse

html如下


        

        
Box-1

        
Box-2

        
Box-3
Box-3
Box-3
Box-3

        

        

 
CSS如下
.father div
         {
         padding:10px;
         margin: 15px;
         border: 1px dashed #111111;
         background-color: #90baff;
         }
 .father .clear
         {
         margin: 0;
         padding: 0;
         border: 0;
         clear: both;
         }

为什么选择器 .father .clear的优先级比.father div高呢?
为什么把.father .clear换成.clear就变成.father div优先了呢?


回复讨论(解决方案)

 我觉得你的格式出现个问题。father ,clear 是属于同一级的,如果你想一起写的话,之间应该加上逗号。

并且 .father div 格式应该是不争取的,应为你想定位的是class名为father 的div ,所以应该改为:div.father

http://developer.51cto.com/art/201009/226852.htm

 我觉得你的格式出现个问题。father ,clear 是属于同一级的,如果你想一起写的话,之间应该加上逗号。

并且 .father div 格式应该是不争取的,应为你想定位的是class名为father 的div ,所以应该改为:div.father

.father .clear加上逗号就是并集选择了 我只想选clean啊

.father div选的是.father里边的div 不是class名为father 的div啊

http://developer.51cto.com/art/201009/226852.htm

“通常我们用1表示标签名选择器的优先级,用10表示类选择器的优先级,用100标示ID选择器的优先级”

懂了 谢谢

Statement:
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