Hey there, I'm currently working on adding random backgrounds to my website through an overlay, but I've hit a roadblock when it comes to displaying them.
Here is the code I'm working with:
.css / .php
#intro {
background:
/* top, transparent black gradient */
linear-gradient(
rgba(0, 0, 0, 0.7),
rgba(0, 0, 0, 0.7)
),
url(/images/<?php echo $selectedBg; ?>);
background-size: 100% auto, cover;
background-attachment: fixed, fixed;
background-position: top left, bottom center;
background-repeat: repeat, no-repeat;
width: 100%;
height: auto;
}
<?php
$bg = array('bg-01.png', 'bg-02.jpg' ); // array of filenames
$i = rand(0, count($bg)-1); // generate random number size of the array
$selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
?>
I have double-checked the file names for bg-01.png and bg-02.jpg and they seem correct. Any help or guidance on what I might be doing wrong would be greatly appreciated.