I'm never sure what the best (most efficient) way to select an element is.
Lets say I have the following layout (extremely simple example)
<div id="navigation">
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</div>
- I want to select my unordered list (ensuring I don't affect any other UL's throughout my site), should I do
#navigation ul {}or assign a class to the UL? - I want to select my list items, again ensuring I only affect those. Should I do
navigation ul li{}or assign a class? - And finally, If I want to select my first link and style it, should I do
#navigation ul li:first-child {}or assign a class?
I appreciate these questions are pretty much the same, but I'm curious when you should use a class and when not to.