亚洲一区在线播放-欧美另类极品videosbest使用方法-亚洲成人av在线播放-黄色录像大片-色悠悠av-91欧美日韩-中文字幕偷拍-综合色婷婷一区二区亚洲欧美国产-一级爱爱片-黑人添美女bbb添高潮了-久久青娱乐-黄色一级视屏-美女国产在线-亚洲九九九九-欧美 日韩 国产 成人 在线观看-星空大象mv高清在线观看免费-国产福利合集-好吊色视频在线观看-尤物综合网-18岁成年人网站

對css中clear元素的理解

2016/11/7 9:10:26   閱讀:1851    發(fā)布者:1851

  clear:left;表示左側(cè)不能有浮動(dòng)元素。

  clear:right;表示右側(cè)不能有浮動(dòng)元素。
clear:both;表示左右兩側(cè)都不能有浮動(dòng)元素。

  但在使用時(shí),還得考慮css優(yōu)先級問題。相同類型選擇器制定的樣式,在樣式表文件中,
越靠后的優(yōu)先級越高 。

  當(dāng)所有元素的clear屬性都設(shè)為right時(shí),由于優(yōu)先級的原因,
并不是所想的那樣:右側(cè)沒有浮動(dòng)元素,而是右側(cè)出現(xiàn)了浮動(dòng)元素。

  比如下面的代碼: 

<html> 
<head> 
<style type="text/css"> 

.div1 
{ 
height:40px; 
width:40px; 
background-color:red; 
position:releative; 
float:left; 
clear:right; 
} 
.div2 
{ 
height:40px; 
width:40px; 
background-color:green; 
position:relative; 
float:left; 
clear:right; 
} 
.div3 
{ 
height:40px; 
width:40px; 
background-color:yellow; 
position:relative; 
float:left; 
clear:right; 
} 
.div4 
{ 
height:40px; 
width:40px; 
background-color:black; 
position:relative; 
float:left; 
clear:right; 
} 
.div5 
{ 
height:40px; 
width:40px; 
background-color:blue; 
position:relative; 
float:left; 
clear:right; 
} 
</style> 
</head> 

<body> 
<div class="div1"> 
</div> 
<div class="div2"> 
</div> 
<div class="div3"> 
</div> 
<div class="div4"> 
</div> 
<div class="div5"> 
</div> 
</body> 

</html>
clear-right

  其中:class優(yōu)先級關(guān)系: div5>div4>div3>div2>div1 

  所以,呈現(xiàn)出下圖情況:

  

 

  當(dāng)所有元素的clear屬性都設(shè)為left時(shí),由于優(yōu)先級的原因,
并不是所想的那樣:右側(cè)可以有浮動(dòng)元素,而是右側(cè)不能出現(xiàn)浮動(dòng)元素。

  比如下面的代碼: 

<html> 
<head> 
<style type="text/css"> 

.div1 
{ 
height:40px; 
width:40px; 
background-color:red; 
position:releative; 
float:left; 
clear:left; 
} 
.div2 
{ 
height:40px; 
width:40px; 
background-color:green; 
position:relative; 
float:left; 
clear:left; 
} 
.div3 
{ 
height:40px; 
width:40px; 
background-color:yellow; 
position:relative; 
float:left; 
clear:left; 
} 
.div4 
{ 
height:40px; 
width:40px; 
background-color:black; 
position:relative; 
float:left; 
clear:left; 
} 
.div5 
{ 
height:40px; 
width:40px; 
background-color:blue; 
position:relative; 
float:left; 
clear:left; 
} 
</style> 
</head> 

<body> 
<div class="div1"> 
</div> 
<div class="div2"> 
</div> 
<div class="div3"> 
</div> 
<div class="div4"> 
</div> 
<div class="div5"> 
</div> 
</body> 

</html>
clear-left

  其中:class優(yōu)先級關(guān)系: div5>div4>div3>div2>div1 。 

  所以,呈現(xiàn)出下圖情況:

  我有時(shí)偶爾還是會(huì)繞暈。。反正,了解了css優(yōu)先級問題,就容易理解了。