【发布时间】:2015-10-02 08:51:03
【问题描述】:
我知道我可以让我的 php 文件表现得像一个 css 文件,我已经做到了。我的问题是如何在另一个 css-php 文件中使用变量?我的带有全局变量的 css.php 文件在 html 列表中的其他文件之前加载,但它似乎没有包含它。
我的html:
<link rel="stylesheet" type="text/css" href="assets/css/variables.css.php">
<link rel="stylesheet" type="text/css" href="assets/css/main.css.php">
我的 variables.css.php 文件:
<?php
header("Content-type: text/css");
$color = "#004D7F";
?>
我的 main.css.php 文件:
<?php header("Content-type: text/css"); ?>
body {
background: <?=$color;?>;
}
但它不起作用,它无法识别变量 $color。所以我尝试在 main.css.php 中添加:
require("/assets/css/variables.css.php");
但是它抛出了一个错误。有人知道答案吗?如何在另一个充当 css 的 php 文件中访问 php 变量?
提前谢谢你!
-- 卡洛斯
【问题讨论】:
-
你能告诉我们
require产生的错误吗?请 -
我不能,因为它是一个 css 文件
-
还有几个问题。您是如何启动 .html 文件的?您是使用 apache(例如 localhost/test.html)还是通过双击文件直接启动?如果你通过双击启动,它不能工作,因为你的 .php 文件不能被执行。
-
当我说 apache 时,我的意思是你的本地网络服务器对不起。