So what are pros/cons between ids/classes/psuedo-selectors?


#1

Are there any real benefits/drawbacks from using any of these items? For instance, why couldn't I just used only id's or only classes in CSS to keep it simple? Is it just user preference?


#2

IDs are meant for individual elements:

<div id="boxone"></div>
<div id="boxtwo"></div>
<div id="boxthree"></div>

Classes are meant for groups:

<div id="boxone" class="box"></div>
<div id="boxtwo" class="box"></div>
<div id="boxthree" class="box"></div>

And pseudo selectors are for styling selectors under a certain circumstance.


#3

What i really like about the psuedo selectors is something not covered in the lessons. You can do odd and even, let me show you:

<p>red</p>
<p>blue</p>
<p>red</p>
<p>blue</p>
<p>red</p>
<p>blue</p>

and then css:

p:nth-child(odd){ color: red; }
p:nth-child(even){color: blue; }

i put it in a bin, with a little tweaking you can also target each third item, if you want, i can show that as well