0

I have been doing CSS and Bootstrap for quite some time now and while watching an online tutorial the teacher mentions these lines but skips the meaning of it.

.navbar-inverse .navbar-nav > .active > a,
.navbar-inverse .navbar-nav > .active > a:hover,
.navbar-inverse .navbar-nav > .active > a:focus{
   color: #fff;
    background: #1A237E;
}

Now I guess that the code in the curly braces will execute if we hover over the link but what's that greater than sign and how does the code works.It will be quite heplful if someone could explain it..:)

john400
  • 392
  • 4
  • 10
  • 20

3 Answers3

2
> is the child combinator, also known as the direct descendant combinator.

See this question for more information

For Example

<html>

<head>
 <style>
  div > p {
   background-color: yellow;
  }
 </style>
</head>

<body>

 <div>
  <p>Paragraph 1 in the div.</p>
  <p>Paragraph 2 in the div.</p>
  <span><p>Paragraph 3 in the div.</p></span>
  <!-- not Child but Descendant -->
 </div>

 <p>Paragraph 4. Not in a div.</p>
 <p>Paragraph 5. Not in a div.</p>

</body>

</html>

source

Here, (when you run this code), you can see that css will be applied only to <p> elements that are wrapped inside <div> tag. It's not directly applied to all the <p> tags

Community
  • 1
  • 1
Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71
0
> means it targets it's direct children.

That means the selector div > p.some_class only selects paragraphs of .some_class that sit directly inside a div, not paragraphs that are nested further within.

Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71
Wim Mertens
  • 1,780
  • 3
  • 20
  • 31
0

The > is to indicate the next selector is a direct child of the preceding selector.

That is .parent > .child {} selects elements with a class of child which are direct child of elements of class parent.

Brett DeWoody
  • 59,771
  • 29
  • 135
  • 184