【发布时间】:2017-03-15 06:20:04
【问题描述】:
出于某种原因,我创建了带有 .php 扩展名的样式表。
在 style.php 上
<?php
/*** set the content type header ***/
/*** Without this header, it wont work ***/
header("Content-type: text/css");
$color = '#ff0000';
$path = 'http://mysite.localhost.com/includes/css/';
?>
//this works
body {
background-color:<?=$color?>;
}
//these don't work
@import url("<?=$path?>foundation.css");
@import url("<?=$path?>app.css");
我不明白为什么@import 根本不起作用。
即使是没有变量的普通 url,它也不起作用。
@import url("http://mysite.localhost.com/includes/css/foundation.css");
我以前使用过 .css 文件。但是我无法像这样使用php变量/常量来替换url。
关于 style.css
@import url("<?php $path?>style.css");
【问题讨论】:
-
您应该尝试使用 SASS 或 LESS,而不是使用 PHP。
-
@mayersdesign,可以浏览
-
您是否检查了浏览器开发者控制台中的网络选项卡以查看是否正在请求这些文件?
-
@MagnusEriksson,刚刚检查过,没有请求那些 css 文件