標籤:
屬性選擇符:
E[att] 選擇具有att屬性的E元素。
<style type="text/css">a[class]{ background-color: red;}</style><body><a href="" class="a">連結a</a><a href="" id="b">連結b</a></body>
E[att="val"] 選擇具有att屬性且屬性值等於valu的E元素。
<style type="text/css">a[class="1"]{ background-color: red;}</style><body><a href="" class="1">連結a</a><a href="" class="2">連結b</a></body>
E[att~="val"] 選擇具有att屬性且屬性值為一用空格分隔的字詞列表,其中一個等於val的E元素。
<style>a[class~="id"]{color: red;}</style><body><ul><li><a href="" class="id 1">連結a</a></li><li><a href="" class="1">連結b</a></li><li><a href="" class="1">連結b</a></li></body>
E[att^="val"] 選擇具有att屬性且屬性值為以val開頭的字串的E元素。
<style>a[title~="163"]{color:red;}</style><body><a href="http://www.163.com/" title="www 163 com">紅色</a><a href="http://www.baidu.com/" title="www baidu com">紅色</a></body>
E[att$="val"] 選擇具有att屬性且屬性值為以val結尾的字串的E元素。
<style>li[class$="a"] {color: #f00;}</style></head><body><ul><li class="abc">清單項目</li><li class="acb">清單項目</li></ul></body>
E[att*="val"] 選擇具有att屬性且屬性值為包含val的字串的E元素。
<style type="text/css">a[href*=".html"]{color:red;}a[href*=".php"]{color:green;}a[href*=".jsp"]{color:blue;}</style><body><a href="http://www.dreamdu.com/css.html?id=1&name=www">夢之都紅色字型</a><a href="http://www.dreamdu.com/css.php?id=2&name=dreamdu">夢之都綠色字型</a><a href="http://www.dreamdu.com/css.jsp?id=3&name=com">夢之都藍色字型</a></body>
E[att|="val"] 選擇具有att屬性且屬性值為以val開頭並用串連符"-"分隔的字串的E元素。
<style type="text/css">a[title~="dreamdu"]{color:red;}</style><body><a href="http://www.dreamdu.com/" title="www dreamdu com">紅色</a></body>
font-family,font-size,font-weight,font-style
<style type="text/css">p { font-family: "宋體";}h1 { font-size:14px ;}h2 { font-weight: normal ;}h3 {font-style: italic;}</style></head><body><p>這是一個標籤</p><h1>這是一個標籤</h1><h2>這是一個標籤</h2><h3>這是一個標籤</h3></body>
font(字型樣式縮寫)
<style type="text/css">/*p{font-style:italic;font-weight:bold;font-size:14px;line-height:22px;font-family:宋體;}*/p {font:italic bold 14px/22px 宋體}</style></head><body><p>這是一個標籤</p></body></html>
text-decoration(文本裝飾線條),text-shadow(文字陰影)
<style type="text/css">p { text-decoration: underline;text-shadow: 2px 2px #ff0000; }</style></head><body><p>這是一個標籤</p></body>
width,height
<style type="text/css">p { width:300px;}div { height:100px; padding: 1px; border:1px solid;}</style></head><body><p>這是一個標籤這是一個標籤這是一個標籤這是一個標籤</p><div>這是一個標籤</div></body>
CSS屬性選擇符