Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS css

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #247998
    Seth-666
    Participant

    hello, why in css exemple:
    body > div > p { backgound-color: black; }
    Why do you use the > and what stands for the > what means ? the > ?

    #248001
    Shikkediel
    Participant

    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.

    https://css-tricks.com/child-and-sibling-selectors/

    #248003
    Seth-666
    Participant

    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

    #248004
    Shikkediel
    Participant

    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 &gt; selector. It that isn’t of importance, you could very well just leave it out.

    #248006
    Seth-666
    Participant

    aha , Thank You Very Much for you’re time :)

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘CSS’ is closed to new topics and replies.