Forum Moderators: not2easy

Message Too Old, No Replies

CSS Background Image

         

cbeyer

10:39 pm on Nov 9, 2007 (gmt 0)

10+ Year Member



I know this is too easy, but for the life of me, I have been staring at code all day and cannot seem to figure this out.

Here is the issue:

In the code below, my background images for the left and right div tags are approx 800px high and if I put that into the style (height: 800px;) then the entire bg image appears. My issue occurs when the venter div content extends beyond 800px or is less then 800px. the bg images do not extend or retract, they just sit there.

Any ideas on how to get them to extract or retract based on the size of the center div tag?

Here is the code:

<html>
<head>

<style>
#mainContainer { width: 600px;background-color: #999;border: 2px solid #000;}
#left { width: 26px; float: left; background-image: url('images/leftBG.gif'); background-repeat: repeat-x;}
#center { width: 548px;float: left;text-align: center; height: 300px;}
#right { width: 26px;float: right;background-image: url('images/rightBG.gif');background-repeat: repeat-x;}
</style>

</head>
<body>

<div id="mainContainer">
<div id="left">ff</div>
<div id="center">gf<br />fff<br />fff<br />fff<br />ffff<br />fff<br />ffff<br />ffff</div>
<div id="right">hhh</div>
</div>

</body>
</html>

Thanks a million,
C

Marshall

6:47 am on Nov 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



cbeyer, welcome to WebmasterWorld.

Had to be the bearer of bad news, but background images will not re-size. Either they will be partially hidden, stop short, or can be repeated (tiled) x, y or both x & y.

Marshall

cbeyer

4:27 pm on Nov 12, 2007 (gmt 0)

10+ Year Member



Bear of bad news as far as css is concerned, sure. however, there is a way to do it.

I was able to pull it off using tables instead of div tags.

so, instead of


<div id="mainContainer">
<div id="left">ff</div>
<div id="center">gf<br />fff<br />fff<br />fff<br />ffff<br />fff<br />ffff<br />ffff</div>
<div id="right">hhh</div>
</div>

I used


<div id="mainContainer">
<table width="1002" border="0" cellspacing="0" cellpadding="0">
<tr>
<td id="leftBG"></td>
<td id="content" valign="top"></td>
<td id="rightBG"></td>
</tr>
</table>
</div>

with similar style to the above. It works. :)

Hope this helps someone in the future.

Peace,
C

Xapti

5:05 pm on Nov 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps your problem is not as clear as you mentioned. You want a stretchy background image, is that right? One that will stretch or condense to fit it's container?
This cannot be done with the CSS background-image property (at least until CSS3 implementation), whether you are using tables or divs, or anything else!
If your situation worked with tables, I would assume you are either running a really quirky browser, or have some javascript running you're not telling us about, or forgetting to tell us something else.

The only way this can be done is with the IMG tag, styled with height:100%;width:100% , and then having the content absolutely positioned over top of it.

[edited by: Xapti at 5:07 pm (utc) on Nov. 13, 2007]