這些僞類並不存在於HTM中,只有當用戶和網站交互的時候才能體現出來html
咱們把:enabled,:disabled,:check僞類稱爲UI元素狀態僞類 兼容IE9以上 check只兼容OPera網站
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> input{width: 200px;height: 30px;border: 1px solid #f00;} /*不可編輯*/ input:disabled{background: #abcdef;border: 1px solid green;} /*可編輯*/ input:enabled{width: 200px;height: 30px;border: 1px solid yellowgreen;} </style> </head> <body> <input type="text" disabled="disabled"> <input type="text"> <input type="text"> <input type="text"> </body> </html>
選擇方法spa
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> div:nth-of-type(2){color: red} </style> </head> <body> <div>0-1</div> <section> <div>1-1</div> <div>2-1</div> <div>3-1</div> </section> <div>0-2</div> <div>0-3</div> <section> <div>2-1</div> <div>2-2</div> <div>2-3</div> </section> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> div{height: 30px;width: 200px;background: #abcdef;margin-top: 10px;} div:empty{background: red} </style> </head> <body> <div></div> <div>second</div> <div>Third</div> </body> </html>
:not(Element/selector)選擇器匹配非指定元素/選擇器的每一個元素code
語法格式htm
父元素:not(子元素/子選擇器) 兼容IE9blog
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> *{margin: 0;padding: 0;border: none;} nav{width: 800px;margin: 0 auto} a{text-decoration: none;color: #333;font-size: 14px;width: 100px;height: 30px;float: left} nav > a{display: block;border-right: 1px solid red} </style> </head> <body> <nav> <a href="#">我是導航</a> <a href="#">我是導航</a> <a href="#">我是導航</a> <a href="#">我是導航</a> <a href="#">我是導航</a> </nav> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> *{margin: 0;padding: 0;border: none;} nav{width: 800px;margin: 0 auto} a{text-decoration: none;color: #333;font-size: 14px;width: 100px;height: 30px;float: left} nav > a:not(:last-of-type){display: block;border-right: 1px solid red} </style> </head> <body> <nav> <a href="#">我是導航</a> <a href="#">我是導航</a> <a href="#">我是導航</a> <a href="#">我是導航</a> <a href="#">我是導航</a> </nav> </body> </html>