user3442381 user3442381 - 1 year ago 64
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download