HTML class attribute with spaces, it is a W3C valid class?

前端 未结 4 1531
南旧
南旧 2020-11-27 18:35

About HTML class attribute, that assigns CSS class (or classes?) to a tag. The use of spaces, like in

....
         


        
4条回答
  •  清歌不尽
    2020-11-27 18:58

    these are two different classes a & b separated by space. see w3c DOCS

    class = cdata-list [CS]

    this attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters.


    If you have two class

    .a { font-weight: bold; }
    .b { font-weight: normal; }
    

    and assign in class="a b" or class="b a", then later class will overwrite the prior class having same property, so font weight will be normal.

    If you change the CSS definition order,

    .b { font-weight: normal; }
    .a { font-weight: bold; }
    

    now the later class is bold, so "overwrite the prior class having same property" results font weight bold.

提交回复
热议问题