P粉3080890802023-09-05 11:21:47
The browser's CSS interpreter will look for any h3
, h4
and h5
elements, and only h2< /code> it will look at Is it within
.info-specs
. Comma or grouped selectors treat everything separated by commas as separate selections.
Possible solutions to your problem are:
/* 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; }
<div class="info-specs"> <p>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.</p> <h2>Heading 2</h2> <h3>Heading 3</h3> <div> <h3>Heading 3 in another div</h3> </div> <h4>Heading 4</h4> <h5>Heading 5</h5> </div>