2014-05-25 62 views
1

我可以使用if语句为css吗?如果其他人为css

这就是我想要的文本的颜色改变:

<?php echo $status; ?> 

将有2状态:待&交付 等待将是红色和交付将是绿色的

我可以像做(对CSS):

.pending {text-decoration:underline; color:red;} 
.delivered {text-decoration:underline; color:green;} 

如果else语句:

if ($status==delivered) 
{ 
    //this is where i don't know what to do and code 
} 
else 
{ 
    //and here 
} 

我应该放什么?或者其他解决方案?

+0

如果您发现任何答案有帮助,请接受它,然后单击乐谱下方的勾号图标。 –

回答

1

使用php/javascript /任何其他语言输出html,并将类分配给所需的任何元素。

纯PHP例子:

<?php 

if(true) { 

echo '<div class="pending">content</div>'; 

} else { 

echo '<div class="delivered">content</div>'; 

} 

?> 

使用变量(PHP + HTML)的另一种方法:

<?php 

if(true) { 

$status = 'pending'; 

} else { 

$status = 'delivered'; 

} 

?> 

<html> 
<head> 
</head> 
<body> 
<div class="<?php echo $status; ?>">content</div> 
</body> 
</html> 
1

如果在PHP中$status变量实际上符合您的类名称,只是用它在你的PHP当显示任何东西是被称呼的时候:

eg如果$status == 'pending',则:

<div class="<?= $status ?>">...</div> 

将呈现

<div class="pending">...</div> 

和符合您.pending规则。