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

前端 未结 4 1528
南旧
南旧 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:52

    That won't work in the CSS file OR the HTML.

    means the div element has class a AND class b AND class c.

    Meanwhile, on the stylesheet side of things, .a b c { property: value; } is not valid because it literally means "element c with ancestor b with ancestor having class a" (and b and c are obviously not valid HTML elements) while .a .b .c { property: value; } would mean "element having class c with ancestor element having class b with ancestor element having class a". Look up CSS specificity rules if this makes no sense to you.

    Use dashes or underscores instead of spaces.

提交回复
热议问题