Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different background for each page?

Tags:

html

css

I am trying to find the easiest way to give each page (from my NavBar) in my website a 'different' photo-background. It seems that once a background is selected that it remains constant for all subsequent pages.

I have Home, About and Contact me links in my NavBar. My goal is to have one photo-background when visitors click on my Home page, another photo-background when they click on About page, third photo-background when they click on my Contact page, etc.

Is there an easy way to do this?

Here is my code so far:

<ul>
    <li><a href="home.html">Home</a></li>
    <li><a href="about.html">About</a></li>
    <li><a href="contact.html">Contact</a></li>
</ul>

My CSS looks like this:

body {background-image:url(greentea.jpg);}
like image 250
C. Felipe Avatar asked May 20 '13 09:05

C. Felipe


2 Answers

You can assign class to body like

for homepage

<body class="home">

for about us page

<body class="about">

The you can use css

body.home{background-image:url(greentea.jpg);}
body.about{background-image:url(greentea.jpg);}
like image 175
edd Avatar answered Sep 20 '22 02:09

edd


Give each tag a unique page ID. In our app we use ruby on rails, so it is id="<%=controller-view%>" kind of architecture.

If your site is static, just hard code in the ID.

<body id="about">

Then in the CSS

body#about {background...}
like image 22
Alex Grande Avatar answered Sep 18 '22 02:09

Alex Grande