Rhino.Freak wrote: Thu Jun 16, 2016 8:30 am
But still, you didn't consider my argument of working style either. Using classes in a better and organized way can help us achieve the benefits you mention of IDs. Besides I don't think I said anything wrong either, as you're trying to portray.
Not using IDs isn't a sin.
Now that's a very different attitude than what your original one was:
"Whatever style you make and whenever you make, just never use any id in the markup. It's really useless and has no benefits over classes."
How isn't that wrong?
Please show a hint of the better and organized way.
I'll show you an example - taken from the previous article - of why I support IDs:
Code: Select all
<ul id="social">
<li><a href="#" class="social-link twitter">Twitter</a></li>
<li><a href="#" class="social-link facebook">Facebook</a></li>
<li><a href="#" class="social-link dribble">Dribbble</a></li>
<li><a href="#" class="social-link gplus">Google+</a></li>
</ul>
The difference in speed between matching all social links that live in a specific #social section and matching all social links that live in possibly multiple .social sections is irrelevant, although the former is still faster.
However, it makes no sense to use a
.social
class instead of a
#social
ID for a parent element which is most likely a unique section of the page. Of course it can additionally have a class if it shares styles (colors, fonts etc.) with other elements.
Better specificity provides for an easier job for the average developer and style author.
Consider the use case of selecting that ul element in Firebug, then locate the CSS and try out the changes, then go change it. If it was an ID, there's no problem. If it were a class, however, you may wonder whether other elements have been affected.
Plus, in the case of the ID I can easily add my own CSS to style child elements. What would I do if there was only a class in place?