/* These select for any h2, h3, h4 and h5 within .info-specs */ .info-specs h2, .info-specs h3, .info-specs h4, .info-specs h5 { text-decoration: underline; } /* These select for ant h2, h3, h4 and h5 that are direct chldren of .info-specs */ .info-specs > h2, .info-specs > h3, .info-specs > h4, .info-specs > h5 { color: red; }
In this example the headings within inf-specs will all be underlined but only the headings that are direct children of info-specs will be coloured red.
瀏覽器的CSS 解釋器將尋找任何
h3
、h4
和h5
元素,並且只尋找h2 它將查看它是否在
.info-specs
內。逗號或分組選擇器將逗號分隔的所有內容視為單獨的選擇。您的問題的可能解決方案是: