/    Sign up×
Community /Pin to ProfileBookmark

CSS background Question

If I have the following code

CSS file:

[CODE]#header {
background: #FFFFFF url(check.php) no-repeat;
height: 1020px;
border-bottom: 0px solid #669900; /* vert fonce */
position: relative;
}[/CODE]

PHP:

[CODE]<?php
header(“Content-type: image/jpeg”);
header(“location:”.’pictures/pictures_’.rand(1,6).’.jpg’);
?>[/CODE]

Is it possible to have the background color of the page set in the css, so that I can match the color of the rotated web background image. So If I have black web ground, I want the html page to be black, and same for a white back ground image would have a white page on refresh.

thanks!

to post a comment
CSS

1 Comments(s)

Copy linkTweet thisAlerts:
@josephbm91Feb 21.2010 — I'd make a multidimensional associative array of the images and their background colors.

$imageWithColors =array(

array('image'=>'picture1.jpg', 'bgcolor'=>'#000000'), //black

array('image'=>'picture2.jpg', 'bgcolor'=>'#FFFFFF'), //white

array('image'=>'picture3.jpg', 'bgcolor'=>'#000099'), //blue

array('image'=>'picture4.jpg', 'bgcolor'=>'#FF0000')); //Red

To make sure the random number matches up, I'd make a variable for the random value. (Since arrays start at 0, I'd change your random numbers accordingly)

$randNumber = rand(0,5);

function getColor(){

if (isset($randNumber)) //If a random number has been generated

$bgcolor = $imageWithColors[$randNumber]['bgcolor'];

else

$bgcolor = "#FFFFFF"; //Assuming default color is white.

echo $bgcolor;

}

Then in the body style, you can do

body{

background-color: <?php getColor(); ?>;

}

And that should do it. This depends on a refresh like you said, so if you were wanting to make it real time, you'd have to use some Javascript.
×

Success!

Help @LUTRELLA spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...