Why All Web Designers Need To Know About The ‘nth-child’

by | Jul 22, 2013 | Unassigned

What is nth-child and What Does it Mean?

Basically the nth-child is a CSS selector that targets specifically the item you need. We use div ID’s to select the div you wish to style but what happens when we have used it multiple times and want to change one of them? That is where the nth-child comes into play.

How Do I Use The nth-child?

To use the nth-child all you have to do is apply it at the end of a selector in your CSS, the same way you would apply “:hover” or “:focus” etc. Place “:nth-child” then in brackets the number of the one you are targeting.

The HTML has three div’s, each with the ID of “box”, yet the output shows the colour of each to be different? That is because the nth-child rule is saying the first div with an ID of box has a background colour of #000 (black). The second div with an ID of box has a background colour of #666 (dark gray) and the third div with an ID of box has a background colour of #CCC (light gray).

Pretty Useful, Right?

But it doesn’t stop there. Nth-child goes even further than just selecting the number down of the item. Another example of what the nth-child can do is target every other item. You do this by changing the number inside the brackets to odd or even.

Last Child

 

First Child

 

One Before Last

 

All Apart From The First Two

 

Conclusion

As you can see the nth-child can in handy to help us deal with a lot of problems, most commonly styling a menu bar where we want different colour backgrounds for each item. Or styling a table that is frequently being updated. Regardless of your reason, I am sure you will find the nth-child as useful as I do.

apijaya apijaya katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp katakjp apijaya apijaya apijaya apijaya apijaya gadaitoto gadaitoto pakjp slot gacor kucingjp Karyawan Muda Raup 20 Juta dari Black Scatter Rahasia Tips Trik analisis pola spin gates of olympus hendra senyum bapak sebelah nemuin keseruan mahjong ways malam minggu bocoran pola mahjong ways anto supir grab setiap pagi bu rina guru sd ketagihan pola scatter gates of olympus cerita mas agus tiap malam main mahjong ways dino tukang service hp hobi analisis gates of olympus filosofi main mahjong ways pak karno tukang bakso kisah ibu tini pedagang sayur jago baca pola gates of olympus mas fajar ngitung peluang mahjong ways dari pengalaman mbak dewi karyawati main gates of olympus jam istirahat nina desainer freelance cek pola gates of olympus pagi pak budi sopir angkot nemuin pola mahjong ways pak santoso pelajari ritme mahjong ways sambil ngopi pak tarno pensiunan pns lebih milih mahjong ways pengalaman pertama mas yoga main gates of olympus ketagihan perjalanan eko fasih baca pola mahjong ways gates of olympus rizal anak kuliah iseng coba mahjong ways nagih siti penasaran mahjong ways kini paham polanya warung kopi pak madi basecamp diskusi pola mahjong ways yanti pegawai minimarket hafal ritme gates of olympus karyawan muda raup 20 juta dari black scatter rahasia tips trik