用過css的同志們都知道,選擇器是非常重要的,如果選擇器使用不當,即使你的css寫的再好,但是不知道要用在哪個元素上,這不是英雄無用武之地嗎?
css,用過的都說好!
最基本的選擇器,id選擇器,類選擇器這些大家早已心知肚明的就不在這裏贅述了,有那功夫趕緊研究一下把妹攻略.
僞類:
屬性選擇器:
input[title=te]{color:red} /*屬性選擇器*/
input[other=wch]{color:blue}
層疊和特殊性
演示代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<style >
a:hover,input:hover{border-color:red;} /*僞類選擇器*/
a:focus,input:focus{border-color:blue}
a:active,input:active{border-color:green}
a:link{border-color:#FFFF00}
a:visited{border-color:#FF33CC}
a + p{color:green} /*選擇兄弟元素,無效好像*/
#nav>li{color:red !important;} /*改變特殊級別*/
#nav li{color:yellow}
#nav li *{color:green} /*通用選擇器*/
input[title=te]{color:red} /*屬性選擇器*/
input[other=wch]{color:blue}
div#ttt{color:#CC0066}
</style>
</head>
<body>
<a href="#" >wch</a>
<input type="text" value="12321" title="test" other="wch" />
<input type="text" value="12321" title="te" other="qqq" />
<input type="text" id="ttt" value="wch" />
<div id="ttt">test element#id</div>
<ul id="nav">
<li>h1</li>
<li>
<ul>123312
<li>x1</li>
<li>x2</li>
</ul>
</li>
<li>h3</li>
</ul>
</body>
</html>