Take the 2-minute tour ×

I have a div which size may differ time to time.

At I set a background image to tat div which image size is fixed. But I need to fit the background image to div at any size.

How could be possible thro' CSS.

Thanks in advance!!!

share|improve this question
Please accept an answer. –  IgalSt Aug 26 '10 at 22:23

2 Answers 2

up vote 1 down vote accepted

The only way to change a size of an image with CSS is when it's an <img> element. I mean that you can do something like that:

img#myBG { width:200px; height:100px; }

If you need it to be a background, you should use 'z-index' and put your img under a the element that holds the content.

Something like this:

<div id="holder">
  <img id="myBG" src="...." />
  <div>my content here</div>

#holder { position:relative; width:200px; height:100px; }
#holder div { position:absolute; top:0; left:0; z-index:2; }
img#myBG { width:200px; height:100px;  { position:absolute; top:0; left:0; z-index:1;  }
share|improve this answer

It's not possible with CSS 2.x that's available in most browsers, but CSS 3 has introduced the background-size property. You can read details here: http://www.css3.info/preview/background-size/

share|improve this answer

Your Answer


