i have the following code example
i am trying to affect all h1 content except the <strong> content
i tried using the child combinator and the :first-child selector and couldnt, thanks in advance
h1 {
background-color: aqua;
}
/* option 1 */
div h1:not( > strong) {
background-color: yellow;
}
/* option 2 */
div h1:not(:first-child) {
background-color: yellow;
}
<div>
<h1>
<strong>STRONG Line #1, Intended to stay the same aqua</strong><br> Line #2, Intended to be Yellow.
</h1>
</div>
<span>Line #3, not in the div at all.</span>
here is the testing console
developer.mozilla
2
Answers
If you target the
strong
element within theh1
directly, you can style it to be different than the rest of the content. See the below as an example:Your colors seem to be round the wrong way in your CSS. If you swap them it simplifies your selectors. Essentially color the
h1
background and then target thestrong
inside theh1
.