.div div div 嵌套會先首先尋找.div的所有后代div元素的dom 然后再在此dom基礎上繼續尋找他的后代div dom 依次類推
a.(這樣的css選擇會出現大量重復,后面的dom屬性會覆蓋前面的屬性)
b. 根元素一定要固定好 倘若寫的是 div div div 第一個div會把頁面里所有div遍歷出來 一一作為查詢根元素
c 雖然多嵌套了幾層 但是可以完全解決css命名重復的問題
<!-- <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>層級選擇器</title> <style> body{ border: 2px solid red; margin: 0; padding: 0; width:300px; } div{ border: 3px solid yellow; margin: 5px; padding: 5px; } div div{ background: pink; } div div div{ background: white; } </style> </head> <body> <div>1 <div>2 <div>3</div> <div><div>9</div></div> </div> <div>4</div> <div>5 <div>6</div> </div> <div> <div> <div></div> </div> </div> </div> </body> </html> --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>層級選擇器</title> <style> body{ border: 2px solid red; margin: 0; padding: 0; width:300px; } div{ border: 3px solid yellow; margin: 5px; padding: 5px; } .div div div{ background: pink; } .div > div > div{ background: white; } </style> </head> <body> <div class="div">1 <div>2 <div>3</div> <div><div>9</div></div> </div> <div>4</div> <div>5 <div>6</div> </div> <div> <div> <div></div> </div> </div> </div> </body> </html>