使用 PHP 更改 CSS 值 [英] Change CSS value by using PHP
问题描述
例如,我有这个 CSS 脚本:
For example, I have this CSS script:
<style>
.header{
background:none:
color:#fff;
}
</style>
然后,我想将标题值更改为:
Then, I would like to change the header value to:
<style>
.header{
background-color:#fff:
color:#000;
}
</style>
值存储在数据库中.让我感到困惑的是哪个应该是最好的:使用 PHP 脚本或 CSS 甚至 javascript.我希望它根据我的数据库中的 CSS 值进行更改,我可以在需要时再次更改(通过使用 PHP 脚本).也许这个问题太笼统了,但是,请给我一些我可以很好地执行的脚本.感谢您的帮助.
The values are stored in database. What makes me confused is which should be the best to do that: Using PHP script or CSS or even javascript. I want it changed based on the CSS value from my database which I can change again when I need it (by using PHP script). Perhaps this question is too general but, please give me some scripts which I can perform it well. Thanks for any help.
推荐答案
首先,将文件的扩展名从(例如) style.css 更改为 style.php .然后将其添加到 css 的第一行:
first, change the extension of your file from (e.g.) style.css to style.php . Then add this to the first line of your css:
<代码>
之后,您可以将背景值定义为变量并轻松更改.
and after that you can define the value of your background as a variable and change it easily.
背景:<?php echo $value;?>
并在您的 php 文件中:
and in your php file:
更新:
<?php $value = "#fff"; ?>
这篇关于使用 PHP 更改 CSS 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!