Mild Fuzz
Mild Fuzz

Reputation: 30671

Can you add an image to the HTML element using CSS?

I am using the following code, but it is having no effect!! Can this be done?

    html {
          background: #d9dbdc url('images/repeat-x.png') repeat-x;
    }

Upvotes: 0

Views: 101

Answers (4)

Pekka
Pekka

Reputation: 449395

This will work if you actually have an image at the specified location, although it's usually applied to the body element. It could be that the body element has a background colour that is covering the image.

Note that paths are relative to the style sheet file, not the HTML file embedding it, so a path pointing to images/repeat-x.png in /css/styles.css would result in /css/images/repeat-x.png.

Upvotes: 2

Mark
Mark

Reputation: 3777

If you are trying to set the background of the entire page I'd recommend:

body { background: #d9dbdc url('images/repeat-x.png') repeat-x; }

Upvotes: 1

Ryan W
Ryan W

Reputation: 6173

make sure the url is correct, you can use browser debug tool like Firebug in firefox to inspect the html

Upvotes: 0

SLaks
SLaks

Reputation: 887295

Yes, it can be done, but it needs to be on the <body> tag.

Your image might not exist, or you might have a different background covering it.

Upvotes: 2

Related Questions