What are the best practices for writing maintainable CSS?

后端 未结 9 1930
礼貌的吻别
礼貌的吻别 2021-02-06 04:25

I am just starting to explore this area and wonder what are the best practices when it comes to production of clean, well-structured and maintainable CSSes.

There seems

9条回答
  •  青春惊慌失措
    2021-02-06 05:15

    I used an own order, convinient for me.

    Rules there were listed in the descending order, and the criterion is rule's affect on the layout. For example:

    .element {
        float:none;
        position:relative;
        top:-2px;
        z-index:100;
        width:100px;
        height:100px;
        margin:10px 0;
        padding:0;
        border:1px solid #000;
        background:#F00;
        font-size:10px;
        color:#CCC;
    }
    

    Of course, in the example above I didn't list all css instructions.

    Particular idea was to keep order of groups, such as:

    1. Positioning
    2. Width and height
    3. Margins and paddings
    4. Borders (and others, affecting element's total dimensions)
    5. Backgrounds, aligning (and others, which don't affect whole page's layout)
    6. Typography

提交回复
热议问题