Reputation: 27
I have:
<style type="text/css">
body{background: url(http://www.mydomain.de/img/<?php
$day = strftime('%A');
if($day == 'Monday') echo 'montag';
elseif($day == 'Tuesday') echo 'dienstag';
elseif($day == 'Wednesday') echo 'mittwoch';
elseif($day == 'Thursday') echo 'donnerstag';
elseif($day == 'Friday') echo 'freitag';
elseif($day == 'Saturday') echo 'samstag';
elseif($day == 'Sunday') echo 'sonntag';
?>.png) no-repeat fixed center top;}
</style>
which sets my background image depending on the weekday. Now in my html I would like to change this body element:
<div class="image center"><img src="pathfromscript"></div>
to display the image as well. How would I set this up?
I tried:
<style type="text/css">
.image.fitcenter img{src=\"/img/<?php
$day = strftime('%A');
if($day == 'Monday') echo 'montag';
elseif($day == 'Tuesday') echo 'dienstag';
elseif($day == 'Wednesday') echo 'mittwoch';
elseif($day == 'Thursday') echo 'donnerstag';
elseif($day == 'Friday') echo 'freitag';
elseif($day == 'Saturday') echo 'samstag';
elseif($day == 'Sunday') echo 'sonntag';
?>.png\" no-repeat fixed center top;}
</style>
but it doesn't work. Thanks.
Upvotes: 2
Views: 460
Reputation: 7819
You're trying to change the source
of the img
with CSS, which is something you can't do. Maybe this is what you were looking for:
If you want to set the source of the img
element, use:
<div class="image center">
<img src="http://www.mydomain.de/img/<?php
$day = strftime('%A');
if($day == 'Monday') echo 'montag';
elseif($day == 'Tuesday') echo 'dienstag';
elseif($day == 'Wednesday') echo 'mittwoch';
elseif($day == 'Thursday') echo 'donnerstag';
elseif($day == 'Friday') echo 'freitag';
elseif($day == 'Saturday') echo 'samstag';
elseif($day == 'Sunday') echo 'sonntag';
?>.png">
</div>
...or if you want to set the image using css to your div
, you should try this:
<div class="image center"></div>
<style type="text/css">
.image.center{
background: url(http://www.mydomain.de/img/<?php
$day = strftime('%A');
if($day == 'Monday') echo 'montag';
elseif($day == 'Tuesday') echo 'dienstag';
elseif($day == 'Wednesday') echo 'mittwoch';
elseif($day == 'Thursday') echo 'donnerstag';
elseif($day == 'Friday') echo 'freitag';
elseif($day == 'Saturday') echo 'samstag';
elseif($day == 'Sunday') echo 'sonntag';
?>.png) no-repeat fixed center top;
}
</style>
Upvotes: 0
Reputation: 18099
If I understand your question correctly, then you are trying to set the image src
in CSS. You cannot change the src
of image from CSS
. You may set the background-image property of an element but not the attribute.
Upvotes: 1
Reputation: 345
Instead of <img>
place another div inside <div class="image center">
and place an image in its background depending on the day
Like this
<div class="image center"><div class="image1"></div></div>
and your css will be
<style type="text/css">
.image .image1{background: url(http://www.mydomain.de/img/<?php
$day = strftime('%A');
if($day == 'Monday') echo 'montag';
elseif($day == 'Tuesday') echo 'dienstag';
elseif($day == 'Wednesday') echo 'mittwoch';
elseif($day == 'Thursday') echo 'donnerstag';
elseif($day == 'Friday') echo 'freitag';
elseif($day == 'Saturday') echo 'samstag';
elseif($day == 'Sunday') echo 'sonntag';
?>.png\" no-repeat fixed center top;}
</style>
Upvotes: 0
Reputation: 598
i see you have class 'image center'
<div class="**image center**"><img src="pathfromscript"></div>
but you after write 'image.fitcenter'
<style type="text/css">
.image.fitcenter img
and why you write src instead background-image try this
<style type="text/css">
.image .center img{background: url(/img/<?php
$day = strftime('%A');
if($day == 'Monday') echo 'montag';
elseif($day == 'Tuesday') echo 'dienstag';
elseif($day == 'Wednesday') echo 'mittwoch';
elseif($day == 'Thursday') echo 'donnerstag';
elseif($day == 'Friday') echo 'freitag';
elseif($day == 'Saturday') echo 'samstag';
elseif($day == 'Sunday') echo 'sonntag';
?>.png\" no-repeat fixed center top;}
</style>
Upvotes: 0