Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div with background image and no content not displaying

Tags:

html

I currently have a div on my page that I have given a background image. This div does not have any content and so it does not display on my page, if I add any content it displays. I would like it display even without content because I want that background image to show up as well as I would like to assign some hover/click events to it.

Is there any way to force the div to display?

like image 646
Collin Estes Avatar asked Jun 10 '11 18:06

Collin Estes


4 Answers

You need to specify a size:

<div style="width: 100px; height: 100px"></div>

You can set the size to the dimensions of your background image, or any other values you desire.

like image 52
George Cummins Avatar answered Nov 12 '22 23:11

George Cummins


You need to specify width and height of that div using css (or min-width and min-height)

like image 22
AR. Avatar answered Nov 12 '22 23:11

AR.


Add a height and a width to the div. You may want to use min-height and min-width and set them equal to the size of your background image.

Adding an empty comment will help browsers that strip empty tags.

like image 3
Jrod Avatar answered Nov 13 '22 00:11

Jrod


Add height and width to it.

Jsfiddle: http://jsfiddle.net/GFTtY/

like image 2
kei Avatar answered Nov 12 '22 23:11

kei