- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
hello, why in css exemple:
body > div > p { backgound-color: black; }
Why do you use the > and what stands for the > what means ? the > ?
It means a direct child of. In your example p
would have to be a first-line descendant of div
and div
in it’s turns can only have body
as it’s immediate parent.
<body>
<div>
<p></p>
</div>
</body>
So this won’t do:
<body>
<header>
<div>
<p></p>
</div>
</header>
</body>
Because div
is not a direct child of body
but of header
instead. Then it would have to be:
body div > p
Meaning any descendant of body
that is a div
. With a direct child that is a p
element.
ok, so is it very importat for me? to write the .class > p or i can just write with no problem .class p {…} because the > is just for me to more organized in my cod
I think it all depends on how specific you want to be with your style. If for example a certain div
has multiple levels nested with p
elements and you only want to target the direct children, you’d need the >
selector. It that isn’t of importance, you could very well just leave it out.
aha , Thank You Very Much for you’re time :)