Remove duplicate CSS declarations across multiple files

前端 未结 6 1620
攒了一身酷
攒了一身酷 2020-12-08 02:40

I\'m looking to remove duplicate CSS declarations from a number of files to make implementing changes easier. Is there a tool that can help me do that?

Right now I\'

6条回答
  •  暖寄归人
    2020-12-08 03:11

    Probably the closest thing to what you're looking for is a css preprocessor and css imports. I like LESS: http://lesscss.org/

    I would do something like

    styles.css
    @site-width: 800px;
    @site-height: 1000px;
    
    #content {
    width: @site-width;
    height: @site-height;
    background: green;
    }
    
    
    styles.game.css
    @import url("style.css");
    
    #content {
    width: @site-width;
    height: @site-height;
    background: blue;
    }
    

    EDIT: I sort of overlooked that you don't even need LESS at all, or the height and width in styles.game.css

    It would just look like

    styles.game.css
    @import url("style.css");
    
    #content {
    background: blue;
    }
    

提交回复
热议问题