I have a basic HTML structure here. The rule div > p
selects the <p>
element directly inside the <div>
, which is expected. But it also selects the <p>
element inside another <p>
that itself is inside the <div>
. I can't figure out the logic here.
HTML:
<div>
<p>
P#1, in the div.
<p>P#2, in the P that's in the div.</p>
</p>
</div>
CSS:
div > p {
background-color: yellow;
}
` tags in the text input are invalid HTML5, and "auto-corrects" them into non-nested `
` tags. You can confirm it by using the inspector (actually there are 3 `p` elements in the browser output, the third one has no content). The resulting outerHTML of the div element is like `"
\n P#1, in the div.\n
P#2, in the P that's in the div.
\n \n`: https://stackoverflow.com/questions/44835895/div-nested-in-p?noredirect=1&lq=1