【问题标题】:css not detected or not loaded未检测到或未加载 css
【发布时间】:2018-05-09 06:50:28
【问题描述】:

我使用 php、html 和 css 创建了一个网站。

我使用<link rel="stylesheet" src="main.css">css 文件调用到 html 文档,但是当我使用 php 编写/回显/打印"<link rel="stylesheet" src="main.css">" 时,即使在控制台上未检测到 css 也未加载.

<!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\" src=\"".$purl."source/lib/css/main.css\"> \n";
                    echo "<link rel=\"stylesheet\" src=\"".$purl."source/lib/css/functional.css\"> \n";
                    echo "<link rel=\"stylesheet\" src=\"".$purl."source/lib/css/header.css\"> \n"; break;
            }
        } else {
            return null;
        } ?>
    </head>
    <body>
        <div class="container">
            <?php $this->sect->getSection(); ?>
        </div>
    </body>
</html>

the console that doesn't show anything

注意:我使用的是 php 7.0.13

【问题讨论】:

  • 什么是 $preq ?什么是 $purl ?它没有在你的脚本中定义
  • 您是否也检查过控制台中的元素?我的意思是生成的代码......如果css文件的链接标签没有嵌入lr,这至少会给你一个想法。
  • 你确定你的 if 条件 if(isset($preq[0]) && $preq[0] != "report" && $preq != "action") 是真的吗?只需在 switch case 之前回显一些值以检查它
  • 你可以尝试在 if 语句 prev 'action' 中写 $preq[0] 吗?
  • $preq from explode("/", str_replace("index.php", "", $_SERVER['QUERY_STRING']));

标签: php html css


【解决方案1】:

看看 Difference between SRC and HREF 您需要 href 属性而不是 src,因此将代码更改为:

   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";

【讨论】:

    【解决方案2】:

    使用 ' 而不是 " 作为您的回声,它会更容易并且可以防止一些问题。

    echo '<link rel="stylesheet" src="'.$purl.'source/lib/css/main.css"> \n';
    echo '<link rel="stylesheet" src="'.$purl.'source/lib/css/functional.css"> \n';
    echo '<link rel="stylesheet" src="'.$purl.'source/lib/css/header.css"> \n';
    

    【讨论】:

    • 这可能会让您感兴趣,使用 " 您可以将 $vars 直接放入其中或 {$this->var} 对象或 {$var['elem']} 数组,而无需使用 " . $var ." 方法。即 echo "{$this->text}";
    猜你喜欢
    • 2015-10-06
    • 2021-04-08
    • 2021-07-09
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 1970-01-01
    相关资源
    最近更新 更多