When to add classes, when to add selectors?
Considering this:
<a class="details" href="#">more…</a>
...
<input type="submit" value="Gogogo">
Say that both should have a very similar appearance, because this is what the designer wants. You do it:
<a class="fancybutton" ...
<input class="fancybutton" ...
.fancybutton { /* ... */ }
or that?
a.details, .someform input[type="submit"] { /* ... */ }
I am struggling with this problem and I am not sure where to go. It seems to be a choice between having a really clear style sheet versus pretty markup that isn't cluttered with classes.
When do you pick one over the other?
, , ( , CSS 2).
( , ) CSS 2 - .
google " " , , ( /) ):
, , , DOM, , . , , .
, node. . , , , . , , - - .
:
-.
, , :
ul li {color: blue;} ol li {color: red;}; :
.unordered-list-item {color: blue;} .ordered-list-item {color: red;}If you should use a child selector, prefer child selectors, which at least only require evaluating one additional node, and not all intermediate nodes to the ancestor.