无法使用绝对目录路径引用样式表

时间:2012-06-29 06:20:57

标签: php path relative absolute

我正在尝试使用以下代码链接到外部样式表:

<?php
    include("/homepages/9/myusername/htdocs/Mobile_Detect.php");
    $detect = new Mobile_Detect();

    if($detect->isiOS()){
        // code to run for the Apple iOS platform.
        echo '<link rel="stylesheet" type="text/css" href="/homepages/9/myusername/htdocs/style.css" />';
    }
?>

不幸的是,我似乎无法建立到style.css的工作链接。我尝试过这个绝对路径,以及一个普通路径,格式化为HTML格式:href="/style.css"href="style.css"href="./style.css"以及其他所有可能性。我究竟做错了什么?如何使这段代码有效?

1 个答案:

答案 0 :(得分:3)

href标记的style属性由浏览器处理。浏览器显然无法访问您的服务器文件系统路径/homepages/9/whatever(更重要的是,它会尝试加载http://yoursite/homepages/9/whatever)。

使用浏览器能够加载的内容更改href属性的值(例如http://yoursite/media/style.css)。