2015-07-11 55 views
0

我有一个文件eksternal CSS “的style.css在Eksternal CSS动态数据

<link rel="stylesheet" type="text/css" id="theme" href="css/style.css"/> 

这部分代码是

.x-navigation > li.xn-logo > a:first-child { 
    font-size: 0px; 
    text-indent: -9999px; 
    background: url("../img/logo.png") top center no-repeat #68A9CF; 
    padding: 0px; 
    border-bottom: 0px; 
    color: #FFF; 
    height: 60px; 
    background-size: 180px 50px; 
} 

我想改变的标志,但如何添加动态数据php在eksternal css,

我尝试这样,但不起作用:(

<?php 
include "connection.php"; 
$dataweb = mysqli_query($con,"select logo from web"); 
$web = mysqli_feth_object($dataweb); 
?> 

.x-navigation > li.xn-logo > a:first-child { 
    font-size: 0px; 
    text-indent: -9999px; 
    background: url("../img/<?php echo $web->logo ?>") top center no-repeat #68A9CF; 
    padding: 0px; 
    border-bottom: 0px; 
    color: #FFF; 
    height: 60px; 
    background-size: 180px 50px; 
} 

有解决方案吗? 帮我谢谢

回答

1

Php在.css文件中不起作用。它只能在.php文件中使用。所以,你必须做的PHP文件下面的标签

<style> 
background: url("../img/<?php echo $web->logo ?>") top center no-repeat #68A9CF; 
</style> 

内,请使用代码在第一个文件中启动Web根目录。

<?php 
include "connection.php"; 
$dataweb = mysqli_query($con,"select logo from web"); 
$web = mysqli_feth_object($dataweb); 
?> 

它会替换你的标志。

+0

我知道在标签头 中使用,但我在eksternal css中有很多动态数据。 :( 喜欢的标志,标志小,色彩网站,图像user.etc –

+0

这是我知道的唯一途径。因为,你不能改变一个.css文件的代码与PHP 这是好的,如果你在外部css中有许多动态数据,只需要在需要重写的head标签中添加那些css,并让其余的css在.css文件中。 – coderpol