PDA

View Full Version : Divs won't display background image



adax
Jul 17th, 2009, 06:26 AM
Hi all, I have this silly problem that im sure is easy to fix but I just can't work it out.

What I am trying todo is make a simple div to display a background image.

Here is my Index.php



<html>
<head>
<link rel="stylesheet" href="test.css" type="text/css"></link>
</head>
<body>
<div id="imagea"> </div>
</body>
</html>


And this is my test.css



#imagea {
background-image:url('img/background.png')
}


Im just trying to get background.png to display.

Thanks for taking the time to read my post.

brandon1
Jul 17th, 2009, 06:40 AM
Divs have no size by default unless you are in IE. (then their default height is 1em)

Just set height and width properties and you will see you image...

heres some code just in case it helps (i used what you typed):
http://www.blendedcodes.com/1ZBpxc7E

a lot of people get used to not having to set the height for an img tag, but divs are different because they arent concerned with what is in the background, they only change their height if you set it explicitly or if the content inside the div grows

adax
Jul 17th, 2009, 06:52 AM
Divs have no size by default unless you are in IE. (then their default height is 1em)

Just set height and width properties and you will see you image...

heres some code just in case it helps (i used what you typed):
http://www.blendedcodes.com/1ZBpxc7E

a lot of people get used to not having to set the height for an img tag, but divs are different because they arent concerned with what is in the background, they only change their height if you set it explicitly or if the content inside the div grows

Thank you for taking the time to read my post and thank you for taking your time to write that example for me. I tried it and it works like a charm.

Thanks again.