-1
How to make each day of the week a different background image ?
-1
How to make each day of the week a different background image ?
1
strftime('%A')
- returns full textual representation of the day Sunday até Saturday
Assign the variable $dia
the value of strftime('%A')
and depending on the day prints the image name as a complement to the url
of property background-image
style sheet
<style type="text/css">
body{background-image: url("http://dominio.com/diretorio/<?php
$dia = strftime('%A');
if($dia == 'Monday') echo 'image1';
elseif($dia == 'Tuesday') echo 'image2';
elseif($dia == 'Wednesday') echo 'image3';
elseif($dia == 'Thursday') echo 'image4';
elseif($dia == 'Friday') echo 'image5';
elseif($dia == 'Saturday') echo 'image6';
elseif($dia == 'Sunday') echo 'image7';
?>.png")}
</style>
Thanks worked out
0
In this case, the solution serves to change the background color, but the concept is the same for the image.
switch($day) {
case 'Monday':
$bg_color = "red";
break;
case 'Tuesday':
$bg_color = "blue";
break;
case 'Wednesday':
$bg_color = "blue";
break;
case 'Thursday':
$bg_color = "gray";
break;
case 'Friday':
$bg_color = "yellow";
break;
case 'Saturday':
$bg_color = "green";
break;
case 'Sunday':
default:
$bg_color = "black";
break;
}
echo "<div style='background-color:$bg_color'>Welcome to my Homepage</div>";
Browser other questions tagged php html css
You are not signed in. Login or sign up in order to post.
This has already been solved in the stack in English, but based on the color background, the idea is the same
– Eduardo Oliveira
Thanks for the help I’ll take a look
– Junior