I want to define the body as a certain colour based upon a variable.
I have been trying things to this affect.
<?php
$seperate_sitting_yes = "Yes";
if($seperate_sitting_yes == "Yes")
{
?>
<style type="text/css"></style>
body {
background-color: blue;
}
</style>
<?
}
?>
Is there a way to do this. I figured as you could use HTML in this way, maybe you could define styles like this...
Any thoughts...Thanks.
In your unedited question you had a </style>
too much, just remove the </style>
tag and it works!!
<?php
$seperate_sitting_yes = "Yes";
if($seperate_sitting_yes == "Yes")
{
?>
<style type="text/css">
body {
background-color: blue;
}
</style>
<?php
}
?>
This is one way to do it
<?php $seperate_sitting_yes = 'Yes'; ?>
<style type="text/css">
body {
background-color: <?= $seperate_sitting_yes == "Yes" ? "blue" : ""; ?>;
}
</style>
or
<?php $seperate_sitting_yes = 'Yes'; ?>
<?php if($seperate_sitting_yes == "Yes") : ?>
<style type="text/css">
body {
background-color: "blue";
}
</style>
<?php endif ?>
or
<?php $seperate_sitting_yes = 'Yes';
if($seperate_sitting_yes == 'Yes'){
echo '<style type="text/css"> body {background-color: "blue";}</style>';
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.