Difference between div>p and just div p

difference between div>p and just div p

It looks all same to me. Can you any one tell me when it is different?

div > p is a sibling selctor. It will only target the first p in the div. div p is a child selector. It will target all p’s in the div.

Thanks,

> is child selector and the other one is descendant .

  • is for sibling.

To clarify: div>p will only select a p that is the direct child of the div (that is, directly inside the div). On the other hand, div p will select any p inside the div, even if it is buried inside other elements. E.g.

div > p

<div>
	[COLOR="#FF0000"]<p></p>[/COLOR]
	<div>
		<div>
			<p></p>
		</div>
	</div>
</div>

div p

<div>
	[COLOR="#FF0000"]<p></p>[/COLOR]
	<div>
		<div>
			[COLOR="#FF0000"]<p></p>[/COLOR]
		</div>
	</div>
</div>

I got this guys… Thanks!! It’s really helping me working with nested css menus… Enjoying it…