Should I aim to add a class/id to everything, or use other selectors

Viewed 1949

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>
  1. 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?
  2. I want to select my list items, again ensuring I only affect those. Should I do navigation ul li{} or assign a class?
  3. 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.

4 Answers
Related