2017-02-20 47 views
1

我有一個情況下,應根據數據庫中的數據更改以下兩個值。 在一個外部的css文件中,我有這個。獲取外部CSS文件中的變量

#wow-container1 { 
    zoom: 1; 
    position: relative; 
    width: 100%; 
    max-width:960px; 
    max-height:360px; 
    margin:0px auto 0px; 
    z-index:90; 
    border:2px solid #FFFFFF; 
    text-align:left; 
    font-size: 10px; 
} 

我的要求是我需要改變最大高度:最大寬度:當存儲在數據庫中的高度和寬度是changed.Is有任何可能的解決方案?

+1

您可以重新配置您的php.ini文件以允許PHP將它解釋爲您的CSS文檔(允許PHP在非.php文件中)。那,或者你可以使用LESS或SASS。你的來電。 –

+0

你可以使用javscript或jquery輕鬆完成。 –

+0

您可以使用JavaScript並完全忽略文件中的CSS。 –

回答

2

嘗試此使用jQuery .css()

var width = "value from DB"; 
var height = "value from DB"; 
$('#wow-container1').css({ 'max-width' : width, 'max-height' : height }); 
+0

這是一個整潔的方式..感謝.. :-) – Vimal

0

你可以得到最大高度,從數據庫最大寬度,在PHP 例:呼喚你的外部CSS文件

<style> 
#wow-container1 { 
    max-width:<?php echo $max_width; ?>; 
    max-height:<?php echo $max_height; ?>; 

} 
</style> 

你可以做後

<?php 
    $max_height='300px';//you have to get the value form db 
    $max_width='300px'; //you have to get the value form db 
?> 

然後寫心愛的CSS部分它在你的編程語言中。

0

的CSS()的jquery是該最佳的解決方案。如果你想使用css改變它, 你必須把數據庫值寫入同一頁面的內聯CSS。像這樣:

<style> 
#wow-container1 { 
    max-width:<?php echo $width; ?>; 
    max-height:<?php echo $height; ?>; 

} 
</style> 


If you want to use jquery .css(), it will be like this : 


var width = "width from database"; 
var height = "height from database"; 
$('#wow-container1').css({ 'max-width' : width, 'max-height' : height });