views:

60

answers:

4

I have two side borders on my website, left and right side... small image about 15x15 which repeats itself down the website... When setting 100% like below, the border only goes "one screen" down (which is 100%). But my website is dynamic and the content changes... I want the border to change along with the total height of the page... How can I do this?

Here is the css:

.bgr_right {
background-image: url(../Graphics/bgr_right.jpg);
background-repeat: repeat-y;
background-position: right;
position: absolute;
top: 0px;
height: 100%;
width: 30px;
right: 0px;
background-color: #E7F5F0;
    }

Here is the HTML DIV:

    <div class="bgr_right"></div>

Also, is position: absolute the right thing to have?

UPDATE: After reading the responses, I thought there has to be a better way... How about using javascipt... Does anybody know if there is a way to, with javascript, get the height of the body? then:

     <div height="javascript_function()" or something...

???

Thanks again

A: 

At the risk of angry comments and loss of reputation - use a table to contain your layout. You get the full-height borders free - they will automatically adjust to the same height as your content.

<table>
  <tr>
    <td class="bgr_left"></td>
    <td class="content"></td>
    <td class="bgr_right"></td>
  </tr>
</table>
Ray
There´s really no need to have empty elements in your markup just to get a background; table, div or any other element. There are always exceptions of course, but this is a pretty simply layout...
jeroen
@Jeroen, having up-voted your comment, I've since *thought* about it. I don't think he was suggesting having *empty* elements, he was just demonstrating the mark-up structure without putting in `<!-- content goes here -->` type filling to the table cells. ...having said that, I don't agree with using tables for layout purposes, however easy it appears.
David Thomas
@ricebowl, the class names of the columns suggest that they are there only for the background. I agree with the not-using-tables part, in my experience everything is done more easily and flexibly using div's / css, but my comment was not just meant for tables, the extra div's the OP uses are redundant as well.
jeroen
A: 

If you have a fixed-width design, you could just use one background image, either on the body or on your content container, depending on the effect you want. This image would be something like:

(left bar)-> | ([x]px space here) | <-(right bar)

With repeat-y, this would give you:

|                |
|                |
|                |
|  content here  |
|                |
|                |
|                |

Then the bars will be as high as your content. If you apply this to <body>, then it will have the height of the body.

Hope this helps.

stephenhay
A: 

There doesn´t seem to be a reason to use a separate div for the background as it´s empty, but it depends if the column width is fixed.

You should apply the background image to the div you want to have a background, that way you can be sure that it will continue below as the div grows.

  1. If your column width is fixed, you can just combine the left and right image in a very wide image that will only repeat vertically.

  2. If your column width is variable, you can have for example the left background in the growing div and the right one on a wrapper div that contains the growing div.

Using the right padding you will get the effect you want.

jeroen
A: 

Alternativly I'd suggest to wrap another two divs around content container and repeat the background aligning it in one div to the left and in the other to the right. I.e.:

<div id="left_wrapper" style="background: url(my_leftimage.png) y-repeat top left;">
<div id="right_wrapper" style="background: url(my_rightimage.png) y-repeat top right;">

  <div id="content">hello world</div>

</div>
</div>

Then if you want it to go height 100% set the html, body and the content containers to 100% height like this in the CSS:

html, body, #content { height: 100%; }

Hope this helps :)

jnpWebDeveloper