Why does this code not work?


#1

https://www.codecademy.com/courses/web-beginner-en-WF0CF/0/2?curriculum_id=50579fb998b470000202dc8b

Okay, why does this code not work?

div h3 div h3 div h3 {
color: red;
}

In the example they mentioned it works like that.

div div p{

             property: value;
}

.
I changed the code to:

div div div p{
 color: red;
}

And it works, but I don't get why does it work like this and not like the error I made before.
Not able to visualize why I went right. (It's bugging me)


#2

what html code do you think you need to fullfil this:

div h3 div h3 div h3 {
color: red;
}

css code?


#3

<div>
      <h3> Hi </h3>
  
     <div>
          <h3>So HTML is my bro</h3>
        <div>
              <h3> And CSS is my senpai</h3>
                 </div>
                         </div>
                              </div>

CSS Code:

div h3 div h3 div h3
{
color: red;
}

#4

lets start with this:

div h3 div

which has the following html code:

<div>
   <h3>
       <div></div>
   </h3>
</div>

see how i nest the inner div inside the h3? h3 div as css selector means div inside h3, not after.


#5

Ah, I got it now. Thanks :slight_smile:


#7