# Need explanation

**URL:** <https://forum.freecodecamp.org/t/need-explanation/116331>\
**Category:** General\
**Tags:** css\
**Created:** [May 16, 2017, 1:47pm UTC](https://forum.freecodecamp.org/t/need-explanation/116331 "2017-05-16T13:47:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrh07](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mrh07/32/66574_2.png) [@mrh07](https://forum.freecodecamp.org/u/mrh07)\
**Post date:** [May 16, 2017, 1:47pm UTC](https://forum.freecodecamp.org/t/need-explanation/116331/1 "2017-05-16T13:47:10Z")

</div>

i need explanation about the code below in CSS ----

section \> nav { background-color: darkgray; }

---

<div class="post-metadata">

**Author:** ![Selhar1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/selhar1/32/104025_2.png) [@Selhar1](https://forum.freecodecamp.org/u/Selhar1)\
**Post date:** [May 16, 2017, 1:50pm UTC](https://forum.freecodecamp.org/t/need-explanation/116331/2 "2017-05-16T13:50:19Z")

</div>

> section \> nav

That’s a [selector](https://www.w3schools.com/cssref/css_selectors.asp), it means that “these rules will apply to all nav elements that are inside section elements”.  
The rest are the “rules”, turning the background of every “nav” element that sits inside a “section” element, darkgrey.

Here’s what a nav element inside a section element looks like:  
`

 `

---

<div class="post-metadata">

**Author:** ![hossuraul](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hossuraul/32/134637_2.png) [@hossuraul](https://forum.freecodecamp.org/u/hossuraul)\
**Post date:** [May 16, 2017, 2:31pm UTC](https://forum.freecodecamp.org/t/need-explanation/116331/3 "2017-05-16T14:31:31Z")

</div>

“\>” selector is for styling every nav element’s that is a direct child of the section element. If you want to style nav you can simply do it like this. section nav { background-color: darkgray; }

---

<div class="post-metadata">

**Author:** ![Selo](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Selo](https://forum.freecodecamp.org/u/Selo)\
**Post date:** [May 16, 2017, 2:34pm UTC](https://forum.freecodecamp.org/t/need-explanation/116331/4 "2017-05-16T14:34:15Z")

</div>

Hi

To be precise that rule “section \> nav” means a nav element that is a child element of section - it’s not enough that it is inside a section element.

The nav -element may be inside a section -element but deeper in the DOM -structure like this and then you need a descendant selector

```
<section>
    <nav> ... </nav> <!-- this is a **child** of section -->
    <div>
       <nav> ... </nav> <!-- this is a **descendant** of section, not child -->
    </div>

```

As CSS selectors you can select all descendant elements by chaining element names in a selector

```
section nav { } <-- this rule selects all nav elements inside a section element
section > nav <-- this rule selects only nav elements that are direct child elements of section

```

Check out: [https://www.w3.org/TR/selectors/#descendant-combinators](https://www.w3.org/TR/selectors/#descendant-combinators)

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:54pm UTC](https://forum.freecodecamp.org/t/need-explanation/116331/5 "2021-01-17T20:54:44Z")

</div>

Closed on January 17, 2021, 8:54pm UTC


