標籤:
1.選擇符:
a.關係選擇符:
1).E F :包含選擇符,選擇所有被E包含的F元素。例如:
<style> p h1 { color:red; }</style>
<body> <p> <h1>嘻嘻</h1> <h1>嘻嘻</h1> </p> </body>
2).子選擇符:E > F,選擇所有作為E元素的子項目F。例如:
<style> p > font { color:red; }</style>
<body> <p> <font>嘻嘻</font> <font><a>嘻嘻</a></font> </p> </body>
3).相鄰選擇符:E + F,選擇緊貼在E元素之後的F元素。例如:
<style> p + h1 { color:red; }</style>
<body> <p> <h1>嘻嘻</h1> <a>嘻嘻</a> </p> </body>
4).兄弟選擇符:E~F,選擇E元素之後所有兄弟元素F。例如:
<style> p ~ h1 { color:red; }
</style>
<body> <p> <h1>嘻嘻</h1> <h1>嘻嘻</h1> </p> </body>
5).id和class選擇符:id/class選取器可以為標有特定ID/class的元素指定樣式。例如:
<style> #nav { font-size:12px;} .header { background:red;}</style><body> <p id="nav">哈哈</p> <header class="header">呵呵</head></body>
6).偽類選擇符:這裡列舉一些常用的。例如:
a標籤的偽類選擇符:
<style> a:link { color:red; } a:visited { color:blue; } a:hover { color:yellow; } a:active { color:green; }</style><body> <a>我是a標籤</a></body>
input標籤的偽類選擇符:<style> input:focus { outline:1px solid red; } iuput:checked { color:red; } input:disable { font-weidh:20px } input:enable { font-weight:30px; }</style><body> <input type="text" name="" value="" id="" / > <input type="text" name="" value="" id="" checked/ > <input type="text" name="" value="" id="" disable/ > <input type="text" name="" value="" id="" enable/ ></body>
<style> ul li:first-child {color:red;} ul li:last-child {color:blue;} ul li:nth-child(3) {color:yellow;} ul li:nth-last-child(2) {color:green;}</style><body> <ul> <li>第一個li</li> <li>第一個li</li> <li>第一個li</li> <li>第一個li</li> </ul></body>
偽類:E:target,匹配相關URL指向的E元素,和錨點差不多。例如:<style> a:target { outline:2px dashed blue; }</style><body><a href="#aaa" id="aaa">嘻嘻</a><a href="#bbb" id="bbb">哈哈</a><a href="#ccc" id="ccc">嘿嘿</a></body>
實現奇偶行樣式:<style> //奇數行樣式; .ul2 li:nth-child(odd){background:red;} //偶數行樣式; .ul2 li:nth-child(even){background:#0F7CCF;} //3的倍數; .ol2 li:nth-child(3n){background:yellow;}</style><body> <ul class="ul2"> <li>test1</li> <li>test2</li> <li>test3</li> <li>test4</li> <li>test5</li> <li>test6</li> </ul> <ol class="ol2"> <li>test1</li> <li>test2</li> <li>test3</li> <li>test4</li> <li>test5</li> <li>test6</li> </ol></body>
CSS筆記二.....