This forum is now read-only. Please use our new forums at discuss.codecademy.com.

CSS Selectors Forum

View Course

514 points
Picture
Submitted by
Sardor Bek
about 2 years ago

16/23 CSS. Why div > p (instead of p:first-child) not working?

Instead of p:first-child{font-family:cursive;} i used div > p{font-family:cursive}. Why it isn't working?

  <!DOCTYPE html>
<html>
    <head>
        <link type="text/css" rel="stylesheet" href="stylesheet.css"/>
        <title></title>
    </head>
    <body>
        <div>
            <p>I'm the first child!</p>
            <p>We're not.</p>
            <p>We're not.</p>
            <p>We're not.</p>
            <p>We're not.</p>
            <p>We're not.</p>
            <p>We're not.</p>           
        </div>
    </body>
</html>

-1 votes

permalink

because all paragraph are nested directly inside the div. div > p would work if the code looked like this:

    <div>
        <p>I'm the first child!</p>
        <span style="display: block>
        <p>We're not.</p>
        <p>We're not.</p>
        <p>We're not.</p>
        <p>We're not.</p>
        <p>We're not.</p>
        <p>We're not.</p>       
       </span>
  </div>

now the first paragraph is the only paragraph nested directly in div. (i uses span, couldn't think of anything else without making the example huge), normally do not nest paragraphs inside span.

2937 points
593d545c83696644420003b7_64554016
Submitted by
stetim94
about 2 years ago