You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP输出link标签后CSS未加载且未被控制台检测问题

问题解决:PHP输出link标签无法加载CSS的原因

嘿,我一眼就发现问题所在了——你在PHP动态输出的<link>标签里,错误地使用了src属性来指定CSS文件路径,而浏览器加载样式表时只认href属性!

核心错误原因

<link>标签引入外部样式表必须使用href属性,src属性是给<script>、<img>这类需要直接嵌入资源的标签用的。用src的话,浏览器根本不会发起CSS文件的请求,自然控制台里看不到加载记录,样式也不会生效。

修正后的代码

把所有src="..."替换成href="..."即可:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title><?php $this->actn->getAction("pageTitle"); ?></title> 
    <?php 
        if(isset($preq[0]) && $preq[0] != "report" && $preq != "action") { 
            switch($preq[0]) { 
                default: 
                    echo "<link rel=\"stylesheet\" href=\"" . $purl . "source/lib/css/main.css\"> \n"; 
                    echo "<link rel=\"stylesheet\" href=\"" . $purl . "source/lib/css/functional.css\"> \n"; 
                    echo "<link rel=\"stylesheet\" href=\"" . $purl . "source/lib/css/header.css\"> \n"; 
                    break; 
            } 
        } else { 
            return null; 
        } 
    ?> 
</head> 
<body> 
    <div class="container"> 
        <?php $this->sect->getSection(); ?> 
    </div> 
</body> 
</html>

额外检查建议

修正后可以打开页面源码,查看生成的<link>标签,确认$purl拼接后的URL是否正确指向CSS文件的实际位置,避免因为路径错误导致样式仍无法加载。

内容的提问来源于stack exchange,提问作者Irvan Hilmi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:03:40