How to include all css kept in a directory?

后端 未结 8 2031
情歌与酒
情歌与酒 2020-12-03 10:20

Is it possible to include multiple css at once in html? Or to be precise, is it possible to include all css placed in a directory, in one go?
like at present what we d

8条回答
  •  暖寄归人
    2020-12-03 11:18

    Unless I'm mistaken, this can be done quite nicely (though still manually) similar to JavaScript.

    ./styles/
       ./layouts/
          all.css      <-- Each subfolder has this
          header.css
          footer.css
          nav.css
       ./main.css      <-- Main CSS file
    

    Inside ./styles/layouts/all.css do you import:

    @import 'layouts/header.css';
    @import 'layouts/footer.css';
    @import 'layouts/nav.css';
    

    Right, this separates the minor logic in CSS organizatoin (which is good IMHO).

    Then, as many "all.css" files in subfolders there are, just include them (Example):

    main.css

    @import 'variables/all.css';
    @import 'layouts/all.css';
    

    I think thats rather nice...

提交回复
热议问题