Posts Tagged ‘add background to div’

Can you put a background image in a div element?

August 23, 2009

The answer is yes. You can put a background picture in a div using background-image in CSS. Below is an example piece of code.


div{
background-image:url("myimage.jpg");
height:100px;
}


It is important to remember the height line if you want the whole image to be displayed; otherwise, you will need a lot of text in the div in order for the whole image appear. If the div does not contain any text, and you do not include a line in the CSS specifying the height of the div; then, the background image will not appear at all.