2016-04-19 34 views
0

我想创建一个动态的CSS。我在每个CSS规则中追加一个变量。我已经尝试使用cookie,session和get方法获取该变量,但它的工作原理与10次中的1次相同。在css文件中使用php代码创建动态css dosen't工程每次..有时动态css不加载只有静态规则在该css被加载

CSS文件(component.min.css):

<?php 
header('Content-type: text/css; charset: UTF-8'); 
header('Cache-control: must-revalidate'); 
$appVar = ""; 

if(!empty($_COOKIE["_adl_appVar"])) 
{ 
    $appVar = $_COOKIE['_adl_appVar']; 
} 
elseif(!empty($_SESSION['_adl_appVar'])) 
{ 
    $appVar = $_SESSION['_adl_appVar']; 
} 
?> 

/* General styles for the modal */ 

/* 
Styles for the html/body for special modal where we want 3d effects 
Note that we need a container wrapping all content on the page for the 
perspective effects (not including the modals and the overlay). 
*/ 
.<?php echo $appVar ?>abs<?php echo $appVar ?>-perspective, 
.<?php echo $appVar ?>abs<?php echo $appVar ?>-perspective body { 
    height: 100%; 
    overflow: hidden; 
} 

.<?php echo $appVar ?>abs<?php echo $appVar ?>-perspective body { 
    background: #fff; 
    -webkit-perspective: 600px; 
    -moz-perspective: 600px; 
    perspective: 600px; 
} 
.container { 
    min-height: 100%; 
} 

.htaccess文件

<IfModule mod_rewrite.c> 
    RewriteEngine On 
</IfModule> 
<FilesMatch "^.*?component.min.*?$"> 
SetHandler php5-script 
</FilesMatch> 

比方说,上述情况下输出将是这个CSS

渲染CSS(不正确)

.container { 
    min-height: 100%; 
} 

Whil e如果它应该呈现这样的: -

/* General styles for the modal */ 

/* 
Styles for the html/body for special modal where we want 3d effects 
Note that we need a container wrapping all content on the page for the 
perspective effects (not including the modals and the overlay). 
*/ 
.9d94584f3c1af62a2078da0ec45702baabs9d94584f3c1af62a2078da0ec45702ba-perspective, 
.9d94584f3c1af62a2078da0ec45702baabs9d94584f3c1af62a2078da0ec45702ba-perspective body { 
    height: 100%; 
    overflow: hidden; 
} 

.9d94584f3c1af62a2078da0ec45702baabs9d94584f3c1af62a2078da0ec45702ba-perspective body { 
    background: #fff; 
    -webkit-perspective: 600px; 
    -moz-perspective: 600px; 
    perspective: 600px; 
} 

.container { 
    min-height: 100%; 
} 

我加载使用jQuery的css文件(请参见下文): -

$("head").append('<link rel="stylesheet" href="path/to/css/component.min.css" id="component-css" type="text/css" media= "screen" />'); 
+0

http://stackoverflow.com/questions/11474345/force-browser-to-refresh-css-javascript-etc – user3791775

+0

要验证这是不是确实是一个缓存的问题尝试做一个卷曲或wget(或相当于)从命令行查看返回的内容。 – apokryfos

+0

为什么你需要首先动态生成这样一个奇怪的类名?我认为在(部分)动态创建的CSS资源中输出它可能是一个相当糟糕的主意;将它直接放入HTML代码中的'