2015-07-11 50 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