I´m trying to get into CSS and have a very simple case where the child selector isn´t working as I expect. I just don´t get it.
My html:
<div>
<p>
<div>Div 1</div>
<div>Div 2</div>
<span>Span 1</span>
</p>
<span>Span 2</span>
</div>
Now whether:
p span {
color: red;
}
NOR:
p > span {
color: red;
}
target any of my span elements. I would assume that both would target my "Span1" span element.
Whereas
div span {
color: red;
}
AND
div > span {
color: red;
}
target BOTH my span elements (I would assume only the first would affect both spans and the latter would affect only the "Span2" span element.
Can someone please help me? Thank you.
` just before the closing `
`. So effectively all your elements become a child (direct) of the topmost `div`.This is the reason why the selectors work in the way they are. – Harry Mar 19 '16 at 09:52