Reputation: 129
Can i use if else statement for css?
This is where i want the color of the text to change:
<?php echo $status; ?>
There will be 2 status: Pending & Delivered Pending will be red color and delivered will be green
Can i do something like (for CSS):
.pending {text-decoration:underline; color:red;}
.delivered {text-decoration:underline; color:green;}
and if else statement:
if ($status==delivered)
{
//this is where i don't know what to do and code
}
else
{
//and here
}
What should i put there? Or any other solution?
Upvotes: 1
Views: 489
Reputation: 2711
Output html with php / javascript / any other language, and assign classes to the whatever element you want.
pure PHP example:
<?php
if(true) {
echo '<div class="pending">content</div>';
} else {
echo '<div class="delivered">content</div>';
}
?>
Another way using variables (PHP + html):
<?php
if(true) {
$status = 'pending';
} else {
$status = 'delivered';
}
?>
<html>
<head>
</head>
<body>
<div class="<?php echo $status; ?>">content</div>
</body>
</html>
Upvotes: 1
Reputation: 36458
If the $status
variable in PHP actually matches your class names, just use it in your PHP when displaying whatever the thing is that's being styled:
e.g. if $status == 'pending'
, then:
<div class="<?= $status ?>">...</div>
will render
<div class="pending">...</div>
and match your .pending
rule.
Upvotes: 1