如何在php样式表中使用@import?

如何在php样式表中使用@import?,php,css,import,Php,Css,Import,出于某种原因,我创建了扩展名为.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 w

出于某种原因,我创建了扩展名为.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("<?php $path?>style.css");  
我以前使用过.css文件。但是我无法使用php变量/常量来替换这样的url

在style.css上

<?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("<?php $path?>style.css");  
导入url(“style.css”);
试试这个:

<style>
    <?php include 'CSS/style.css'; ?>
    </style>

试试这个:

<style>
    <?php include 'CSS/style.css'; ?>
    </style>

尝试另一种

   <?php
    $css = file_get_contents('CSS/style.css');
    echo $css;
    ?>

尝试另一种

   <?php
    $css = file_get_contents('CSS/style.css');
    echo $css;
    ?>


不要使用PHP,你应该尝试SASS或更少。你可以浏览到吗?@mayersdesign,可以浏览吗?你是否检查了浏览器开发人员控制台中的“网络”选项卡以查看这些文件是否被请求了?MagnusEriksson,刚刚检查了,那些css文件没有被请求,而不是使用PHP,你应该尝试SASS或更少。你能浏览到吗?@mayersdesign,能浏览吗?你检查过浏览器开发人员控制台中的“网络”选项卡了吗?这些文件被请求了吗?@MagnusEriksson,刚刚检查过,那些css文件没有被请求头(“内容类型:text/css”);已经告诉它一个样式表,因此不需要使用tagI确定OP将文件作为css文件(标题(“内容类型:text/css”);已经告诉它一个样式表,因此不需要使用tagI确定OP将文件作为css文件包含(这很有效,非常感谢..我只是想理解为什么@import在这里不起作用?这很有效,非常感谢..我只是想理解为什么@import在这里不起作用?