Is there a maximum length for the class name in CSS?

前端 未结 6 1241
礼貌的吻别
礼貌的吻别 2020-12-29 19:50

Is there a maximum number of caracters for the name of a class in CSS ?

6条回答
  •  無奈伤痛
    2020-12-29 20:25

    To add to what others have written, would just like to add if - like me - you find you sometimes end up with crazy long names (because you like being descriptive) then it's worth bearing in mind selectors, which also promotes style re-use and helps keep things easy to read.

    e.g.

    h1 {
       1.5em;
    }
    
    styledParagraph {
       font-size: 1em;
    }
    
    /* Override the default font size if the styledParagraph element is inside an element with the class articlePage */
    .articlePage .styledParagraph {
        font-size: 1.5em;
    }
    
    /* Make all 

    elements in .articlePage -> . styledParagraph larger than the default */ .articlePage .styledParagraph h1 { font-size: 2em; }

    This is very widely supported (even in MSIE 6) and it's much easier to read than a class name like .articlePageStyleParagraphHeading.

提交回复
热议问题