tags:

views:

71

answers:

5

I need to apply different background images to the home page < html > tag and the inside pages of a site. In order to do this the references need to be unique.

Without using class or id, how do I differentiate between the tags?

I tried this, but it doesn't validate:

<html class="inside"...

Thanks!

+1  A: 

If you're talking about different background images for different pages, I guess you'll need to create a different stylesheet for each different background you want, and just make sure to include the appropriate stylesheet from each page.

David Zaslavsky
Why? He can just put an id on home and override the default body background.
Graphain
Or just include a single statement inline stylesheet on each different page. `<style> html { background: url(whatever.png); } </style>` @Graphain because `<body>` might not cover the entire viewport, and sometimes it can be useful for page layout to set some styles to html and avoid adding extra markup
MooGoo
MooGoo, I think this inline stylesheet might be the best option. Put this in as an answer instead of a comment and I'll award you the point! Thanks.
fmz
The inline stylesheet works, but it'd get awfully inconvenient if you want to change the background image used on a whole class of pages... besides, there are some (only semi-relevant) arguments against using inline stylesheets, having to do with properly encoding CDATA and such. Maybe not worth caring about.
David Zaslavsky
But would it be any more inconvenient than including a specific stylesheet for each different page?
MooGoo
In that one particular scenario where you want to change all pages that use a particular background image to use a different background image, yeah, since with an external stylesheet you only have to change the image URL in one place. In general, though, I could see an external stylesheet not being worth it for one line.
David Zaslavsky
I'm gonna be backwards about this and say just change the image itself. But yea, the inline stylesheet is probably best suited for pages that have unique backgrounds that are not shared. I guess that is how I was thinking about the problem. Either way some kind of server logic should be used to determine each pages background that does not require hard coding.
MooGoo
+2  A: 

Add the class to your body element, where it is valid.

Then do

body.inside {
    background-image: url(/path/to/it.png) repeat;
}
alex
The body already has a unique background image.
fmz
Alex, I agree that in general this is the right way and the best way to do things, however, I need one background image on the body and another on the html, which does work. The problem is having a unique background image on the home page and another on the inside pages. The solution, pointed out by MooGoo below works the best here because I can assign a unique background image to each page through an inline stylesheet.
fmz
A: 

You want this:

CSS:
#home { background: ... ; }
body { background: ... ; }

HTML:
<body id="home">

</body>

Other pages:
<body>

</body>
Graphain
A: 

You should consider using IDs. That way you can keep all the references to your background images in your CSS file. E.g.

#background-main  { background-image:url(background-main.jpg) }
#background-page1 { background-image:url(background-page1.jpg) }
#background-page2 { background-image:url(background-page2.jpg) }

You would then just have to reference the ID of the background image you want to have displayed. E.g.

<body id="background-main">

Alternatively, you could use classes.

This approach will make it easier for you to maintain your site.

Gert G
Gert, this is very wise, but overlooks the necessity of an background image on the html element.
fmz
Then just add the `ID` to the `HTML` tag. E.g. `<html id="background-main">`
Gert G
+1  A: 

Inline stylesheet for each different page:

<style> html { background-image: url(someimage.png); } </style>
MooGoo
@fmz point whoring...I feel dirty...just a little
MooGoo
Hey, given my situation, this really was the best solution. Humbly take credit where credit is due. Thanks for the help!
fmz