<分区>
标签 php css codeigniter
<分区>
我想要一个基于数据库的动态样式颜色
// the first line is static
$row_color = $value['late'] >= 60 ? ' style="color:red;"' : '';$
// and this code is not working
$color = $value['color'];
$row_color = $value['status'] == "OT" ? ' style="color: $color"' : '';
最佳答案
您不能将 php 放在 css 文件中。您可以做的是在您的 .css 文件中创建两个不同的类,然后在 php 页面中您可以根据条件加载这些类。
例如file.css 可能有
.color-red { color: red; }
.color-blue { color: blue; }
在 file.php 你可以放
$color = ($value['late'] >= 60) ? 'color-red' : 'color-blue';
在你的html标签中你可以像这样使用它
<div class="<?php echo $color?>">
关于php - 如何将 php 变量放入 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55625866/
相关文章:
php - 如何在 codeigniter 中集成 razorpay 支付网关
forms - ReCaptcha 无效 + CodeIgniter 表单助手 = 表单数据丢失
php - 简单的 Javascript 加密,PHP 使用共享 key 解密
html - 带有 'display: table-cell' 的 div 的 css 选择器
css - 应用 * :first-child +html in same CSS file with different attributes
php - 如何将 PHP 整型变量中的整型值传递给 JS?