user3442381 user3442381 - 1 month ago 6
CSS Question

How to select only for the first of divs with equal names?

How to select only for the first of many divs with equal names with CSS? For example i have this:

<div class="div">dsdas</div>
<div class="div">123</div>
<div class="div">73</div>
<div class="div">63</div>
<div class="div">53</div>
<div class="div">45</div>


How to select only the first div(with class "div")?

Answer

Use the pseudo-selector :nth-of-type(). To select the first element with the class "div", do it like this:

.div:nth-of-type(1) {

}

Working DEMO