使用PHP的动态CSS [英] Dynamic CSS using php

查看:70
本文介绍了使用PHP的动态CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在研究PHP Codeignitor框架。我假设某些属性(例如颜色,字体等)保存在数据库中的某个字段中。我要做的是,在CSS文件中有一些带有默认值的类。像前我有一个CSS类,如下所示:

Currently, I am working on PHP codeignitor framework. I have some properties suppose like color,fonts etc. saved in my database for one of fields. All I want to do is, I have some classes in the css file with default values. Like ex. I have a css class as below:

     .text_box{
           color: pink;
           text-decoration: none;
           background-color: transparent !important;
           transition: all 0.2s ease-in-out 0s;
       }
       .text_box:hover{
             color: blue;
             text-decoration: none;
             background-color: transparent !important;
             transition: all 0.2s ease-in-out 0s;
        }

在我的数据库中,我为文本框设置了color属性为黄色。我想动态更改它。意味着当我从输入字段更改该颜色时,它应该会自动转换为css属性中我想要的颜色。

In my database, I have set color property as yellow for text box. I want to change it dynamically. means when I change that color from input field, it should automatically get converts into the color I want in css property.

我不确定我的问题是否正确。我浏览了许多链接,但没有得到与我的方案相关的解决方案。

I dont know exactly whether my question is correct or not. I have goggled many links but didn't get the relevant solution to my scenario.

使用PHP如何创建动态更改。

Using PHP how can create such dynamic changes.

谢谢。

推荐答案

您可以使用jQuery。

You can do it using jQuery.

var color = "value from DB";
$('.text_box').css({ 'color' : color, });

或在PHP中:

<?php
$color = 'value from DB'; //you have to get the value from db
?>
<style>
.text_box { 
color: <?php echo $color; ?>;
}
</style>

希望这项功能有效。

这篇关于使用PHP的动态CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆