How to use relative paths for included files such as .css

后端 未结 8 1285
梦如初夏
梦如初夏 2020-12-29 15:07

I have a header.php file which contains a .css file link.

When I \"include\" header.php into another php file in different fo

8条回答
  •  天命终不由人
    2020-12-29 15:32

    You have few options, which i've tried to gather here

    base href

    
    
    
    

    What it does, is sets all hrefs to point to certain path. With this set, you can use and successfully load mycss.css file even if you're page is deep down in http://www.mysite.com/pages/2012/public/secret_folder/myownphpfile.php

    absolute paths

    You can always use aboslute paths such as, but it can be a pain to change folders of files later on.

    
    

    defined pats

    As @Discomatt told, using PHP defined paths is a easy way to keep things working. Downside; you have to use PHP. if you use it anyways, no problems ^^

    define('CSSDIR', 'http://www.mysite.com/css/);
    
    

提交回复
热议问题