How to include all css kept in a directory?

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

    You could create a master stylesheet that you include in every page, and within that css file you can use @import to include the others.

    This doesn't solve the problem of having to manually include each individual css file, but at least it encapsulates it within the master stylesheet so you don't have to repeat all of the references in every html file. If you add additional css files you will only need to add a reference in the master css and all pages will get access to it.

    Example HTML CSS Reference:

    
    

    Example Master CSS (master.css):

    @import url(style1.css);
    @import url(style2.css);
    @import url(style3.css);
    

    Read more about when to use @import and it's compatibility with older browsers.

提交回复
热议问题