more… ...

When to add classes, when to add selectors?

Considering this:

<a class="details" href="#">more&hellip;</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?

+3
source share
5 answers

CSS- - . , , , , , , , " ".

+5

IE6 input[type=submit], , , .

+1

, , . , CSS, .

0

, , . , -.

, , .. class= "- ".

0

, , ( , 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.

0
source

Source: https://habr.com/ru/post/1723101/


All Articles