Click to See Complete Forum and Search --> : background inside a div


weee
09-18-2004, 08:17 AM
Hi There.

I have a div which is 700 width and I want to have an image in the middle of the div. I understand that the best way to make it happen is to get the image to functions as a background image. How can I do it?

Thanks!

gil davis
09-18-2004, 08:46 AM
Something like this:
<div style="background: url('imagefilename.ext') no-repeat 50%">

Mr J
09-18-2004, 08:46 AM
Please try the following


<div style="width:700px;height:400px;border:1px solid blue;background: url(image.jpg) no-repeat 50% 50%"></div>

weee
09-18-2004, 11:16 AM
?

Mr J
09-18-2004, 11:26 AM
When using percentages or lengths, the horizontal position is specified first, followed by the vertical position. A value such as 20% 65% specifies that the point 20% across and 65% down the image be placed at the point 20% across and 65% down the element. A value such as 5px 10px specifies that the upper left corner of the image be placed 5 pixels to the right of and 10 pixels below the upper left corner of the element.