How to include all css kept in a directory?

后端 未结 8 2023
情歌与酒
情歌与酒 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:13

    There may be some possible workarounds:

    • Consider the idea of importing a PHP page (e.g. ./tabs_css/allcss.php) which concatenates and returns all the css in the directory. This may be a little CPU intensive.

    • Consider creating a combo css file which is concatenation of all of your CSS files. This might be possible to create automatically by adding special hooks to your version-control system.

    0 讨论(0)
  • 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...

    0 讨论(0)
提交回复
热议问题