/    Sign up×
Community /Pin to ProfileBookmark

Complex nth child selection

Hey guys , i just saw some scary code , it uses the nth child selector , please have a look and explain it to me .

HTML ::

[CODE]
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
<div>18</div>
<div>19</div>
<div>20</div>
<div>21</div>
<div>22</div>
<div>23</div>
<div>24</div>
<div>25</div>
<div>26</div>
<div>27</div>
<div>28</div>
<div>29</div>
<div>30</div>
<div>31</div>
<div>32</div>
<div>33</div>
<div>34</div>
<div>35</div>
<div>36</div>
<div>37</div>
<div>38</div>
<div>39</div>
<div>40</div>
<div>41</div>
<div>42</div>
<div>43</div>
<div>44</div>
<div>45</div>
<div>46</div>
<div>47</div>
<div>48</div>
[/CODE]

CSS::

[CODE]
div:nth-child(12n – 9),
div:nth-child(12n – 7),
div:nth-child(12n – 5),
div:nth-child(12n – 2),
div:nth-child(12n) {
color: red;
}
[/CODE]

Fiddle:: [URL=”https://jsfiddle.net/mvve6kub/”]https://jsfiddle.net/mvve6kub/[/URL]

What does the

[CODE]12n – 9[/CODE]

, really mean ?

Gautam.

to post a comment
CSS

4 Comments(s)

Copy linkTweet thisAlerts:
@cootheadMar 08.2015 — Hi there gautamz07,

[indent]

does this help...

n=1:
[list=1]
  • [*][color=navy]12n=12[/color]

  • [*][color=navy](12-9)=3[/color]

  • [*][color=navy](12-7)=5[/color]

  • [*][color=navy](12-5)=7[/color]

  • [*][color=navy](12-2)=10[/color]

  • [*][color=navy](12)=12[/color]

  • [/list]

    n=2:
    [list=1]
  • [*][color=navy]12n=24[/color]

  • [*][color=navy](24-9)=15[/color]

  • [*][color=navy](24-7)=17[/color]

  • [*][color=navy](24-5)=19[/color]

  • [*][color=navy](24-2)=22[/color]

  • [*][color=navy](24)=24[/color]

  • [/list]

    n=3:
    [list=1]
  • [*][color=navy]12n=36[/color]

  • [*][color=navy](36-9)=27[/color]

  • [*][color=navy](36-7)=29[/color]

  • [*][color=navy](36-5)=31[/color]

  • [*][color=navy](36-2)=34[/color]

  • [*][color=navy](36)=36[/color]

  • [/list]

    n=4:
    [list=1]
  • [*][color=navy]12n=48[/color]

  • [*][color=navy](48-9)=39[/color]

  • [*][color=navy](48-7)=41[/color]

  • [*][color=navy](48-5)=43[/color]

  • [*][color=navy](48-2)=46[/color]

  • [*][color=navy](48)=48[/color]

  • [/list]

    [/indent]

    [i]coothead[/i]
    Copy linkTweet thisAlerts:
    @gautamz07authorMar 08.2015 — @ccothead .... thanks ! .
    Copy linkTweet thisAlerts:
    @cootheadMar 08.2015 — [indent]

    No problem, you're very welcome. ?

    [/indent]

    [i]coothead[/i]
    ×

    Success!

    Help @gautamz07 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...