mardi 3 février 2015

What to use instead of IDs in selectors in CSS


I recently installed a csslint package for my Atom text editor. I keep getting warnings saying "Don't use IDs in selectors." I found this weird since I've always been using IDs in selectors in CSS, and I haven't really run into any coding or syntactic problems using them.


On StackOverflow, I found posts, like this one, stating that I shouldn't use IDs because they have priority over classes. However, I found another post that states I should use IDs because they have priority over classes. I understand both of these posts, but I still don't know if I should continue to use them or not.


Lets say I have this code as an example:


HTML



<div id="opening-subject-container">
<div class="subject"></div>
<div class="subject"></div>
<div class="subject"></div>
</div>
<div id="body-subject-container">
<div class="subject"></div>
<div class="subject"></div>
<div class="subject"></div>
</div>


CSS



.subject {
width: 100%;
height: 20px;
}
#opening-subject-container .subject {
background-color: red;
}
#body-subject-container .subject {
background-color: blue;
}


where I want the first subjects in the opening container to be red and the remaining subjects in the body container to be blue.


If I shouldn't ever use IDs in CSS selectors, what should I use instead?





Aucun commentaire:

Enregistrer un commentaire