I have the following in my < head > section
<?php
$rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
$color = '#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
?>
I have the following in my < body >
<div class="featured-details" style="background-color: <?php echo $color; ?>;">
When my page loads, the CSS says the following:
<div style="background-color: ;" class="featured-details">
i.e. it would seem no color is being generated.
Can anyone help?
It could be that your code snippet in your head is executed in a different scope than the code in your body and thats why
$coloris blankif
$coloris in a function try making it a global variable instead.You would need to add
global $color;before you set it in the head and also at some point in the body.