How to import/include a CSS file using PHP code and not HTML code?

后端 未结 14 1907
無奈伤痛
無奈伤痛 2020-11-28 11:11

I have googled a lot but it seems that I am doing something wrong.

I want to do this:



        
14条回答
  •  日久生厌
    2020-11-28 11:31

    To use "include" to include CSS, you have to tell PHP you're using CSS code. Add this to your header of your CSS file and make it main.php (or styles.css, or whatever):

    header("Content-type: text/css; charset: UTF-8");
    

    This might help with some user's connections, but it theoretically (read: I haven't tested it) adds processor overhead to your server and according to Steve Souder, because your computer can download multiple files at once, using include could be slower. If you have your CSS split into a dozen files, maybe it would be faster?

    Steve's blog post: http://www.stevesouders.com/blog/2009/04/09/dont-use-import/ Source: http://css-tricks.com/css-variables-with-php/

提交回复
热议问题