【问题标题】:Load CSS from PHP like loading IMG从 PHP 加载 CSS 就像加载 IMG
【发布时间】:2023-03-12 21:49:01
【问题描述】:

我可以使用以下代码来加载 IMG 文件:

<img src="http://www.www.com/image-name.php"/>

现在,我想知道如何从外部 php 加载 CSS?

<link rel='stylesheet' href='http://www.www.com/main-css-file.php' />

原因是因为 css 将在主题文件夹中,其中包含一个完全拒绝的 htaccess 文件。

任何帮助表示赞赏!

【问题讨论】:

  • 错误。像那样。为什么会这样?
  • 我的意思是从www.com/main-css-file.php 加载 - 我是否缺少标题类型? - 原因是因为 css 将在主题文件夹中,其中包含一个完全拒绝的 htaccess 文件。
  • 跟图片一样。 (除非您将内容类型设置为“This is CSS”而不是“This is JPEG”)

标签: php html css


【解决方案1】:

很容易。

<?php header('Content-type: application/pdf'); ?>

h1 {
    font-size: 40px;
}

h2 {
    font-size: 30px;
}

p {
    font-size: 14p
}

【讨论】:

    【解决方案2】:

    返回数据前需要将Content-Type标头设置为text/css

    <?php
      header('Content-Type: text/css; charset=utf-8');
      $color = '#d0e4fe';
    ?>
    
    body {
        background-color: <?php echo $color ?>;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 2011-04-18
      • 1970-01-01
      • 2021-07-02
      • 2023-04-02
      • 2023-03-18
      • 2018-12-13
      相关资源
      最近更新 更多