7

I need to have images that extend along the left and right sides of my main body div (actually for a sort of drop-shadow effect under the div).

This would be simple if it wasn't for the fact that I want this div to be expandable, and I need it to work in IE7 and IE8, and I want it to extend to at least the bottom of the page.

I tried using polyfills to get CSS3 magic going but they weren't working either (I tried PIE and some filters without any luck).

I feel like I've tried everything...which brings me here! This is as far as I've gotten via just CSS/html, I feel like I should be able to get it to work but so far no cigar:

<div class="left-image">
<div class="right-image">
main body text
</div>
</div>

with the following css:

html,body{
    height: 100%
}
.left-image{
    background: transparent url('image/url.png') repeat-y top left;
    min-height: 100%; /*this alone works for making outer div extend browser & content height*/
    min-width: 960px;
    max-width: 1280px;
    margin: 0 auto;
}
.right-image{
    background:  transparent url('image/url.png') repeat-y top left;
    height: 100%; /*this only makes the div the height of its content*/
}

This results in the .left-image div filling the height of the browser window or the height of the content (whichever is larger), but the .right-image div only fitting the height of the content (so if the content is smaller than the browser window it won't fill it).

Any way around this? Just use jQuery?

Sabrina Leggett
  • 9,079
  • 7
  • 47
  • 50

9 Answers9

2

This is a common problem without an easy solution. CSS3 will solve it but supporting older browsers means its not going to go away any time soon.

check out

http://www.alistapart.com/articles/fauxcolumns/

and see if this points you in the right direction. You basically need to fake it (faux columns) or use javascript as far as I am aware.

anon-e-mouse
  • 126
  • 3
  • Since this is a top rated Google hit, I just wanted to add that "CSS3 will solve it" means http://stackoverflow.com/a/16837667/1463507 – kqr Oct 20 '14 at 14:52
1

One cheap solution I have used in the past has been to set the top and bottom posistions to zero.

.left-image{ 
  background: transparent url('image/url.png') repeat-y top left; 
  /*min-height: 100%;*/
  position: absolute;
  top: 0px;
  bottom: 0px;
  min-width: 960px; 
  max-width: 1280px; 
  margin: 0 auto; 
}
.right-image{ 
  background:  transparent url('image/url.png') repeat-y top left; 
  /*height: 100%;*/ 
  position: absolute;
  top: 0px;
  bottom: 0px;
}
Shredderroy
  • 2,860
  • 2
  • 29
  • 53
  • Thanks! That works perfectly in terms of getting the div to fit to the screen, but if I scroll down in the document the div doesn't stretch for the content (it stops as soon as I scroll). I wonder if I could do something with position: fixed (maybe make the content in separate div? I'll play with it...) – Sabrina Leggett Jan 22 '12 at 23:06
1

You'd probably be better off using a background image - see http://jsfiddle.net/ZXpyT/ for an example. Note that this assumes the body content would be 960px wide; the idea would be to create an image (repeatable vertically) which replaces the current separate left / right images.

Conan
  • 2,659
  • 17
  • 24
  • The background needs to expand and shrink with the main div. The main div has a min-with of 960px and a max-width of 1280px and I need the background image to border it at any width, which is why I need it to be two separate images. – Sabrina Leggett Jan 27 '12 at 11:13
1

you can specify multiple backgrounds to your wrapper div instead of to the 2 divs, like this

.wrapper{
background: url('left.jpg'),url('right.jpg');
background-repeat: repeat-y, repeat-y;
height:100%;
}

sorry i missed the browser matrix you want to support... well here it goes..try this..this worked for me in all browsers

<html>
    <head>
        <title></title>
        <style type="text/css">
            .left-image{
                background:grey;
                min-height:100%;
                height:100%;
                width:100%;
                position:absolute;
            }
            .right-image{
                background:#eee;
                min-height:100%;
                height:100%;
                width:50%;
                margin:0 auto;
            }
        </style>
    </head>
    <body>
        <div class="left-image">
            <div class="right-image">
                main body text
            </div>
        </div>
    </body>
</html>
Abhidev
  • 7,063
  • 6
  • 21
  • 26
  • http://www.w3schools.com/css3/css3_backgrounds.asp multiple backgrounds don't work in IE8 and bellow. Haven't been able to get PIE working and I'm not sure if it's worth fighting with it or just using JS. – Sabrina Leggett Jan 27 '12 at 11:05
  • Nice try! :) If you put text that extends more than the height of the browser window it doesn't work. I'm telling you...it looks easy but not so much! – Sabrina Leggett Feb 12 '12 at 14:54
  • another way could be...giving position:fixed to left-image div. Have you tried this? – Abhidev Feb 13 '12 at 06:00
1

Why don't you give .left-image height:100%? Some browsers to get 100% browser width/height, you have to set every containing element to 100%.

Belladonna
  • 3,824
  • 2
  • 24
  • 33
1

How about height: inherit; ? It should take the parent tag's height as is.

Giannis
  • 813
  • 7
  • 13
  • this works when the content is at least the height of the page but I needed the divs to be at least as high as the browser window. I think I read somewhere that height: 100% doesn't work when the outer element has an auto value and min-height is considered auto, this is probably the case with inherit as well – Sabrina Leggett Mar 07 '12 at 00:40
0

You're using min-height on the left-image, why not on the right-image too?

JuanOjeda
  • 864
  • 7
  • 11
-1

I ended up using:

$(".left-image, .right-image").height($(document).height());

(I used it on document load, on window resize, and when ajax calls are made that might expand the page)

I think my new rule is going to be that if something takes me more than twenty minutes to figure out using css alone I'm going to go the simple way and use javascript/jquery...

Sabrina Leggett
  • 9,079
  • 7
  • 47
  • 50
  • 2
    Your attempts in your question show you don't know CSS well and falling into the "use jQuery" trap means you've chosen to give up instead of learning how it works. – Rob Jan 23 '12 at 13:53
  • steering me in the right direction is more useful than criticizing my knowledge...I don't know everything about CSS or else I wouldn't be asking here. – Sabrina Leggett Jan 23 '12 at 13:58
  • Please supply an answer then. There may be an alternative method I'm not seeing but the way I'm currently trying it definitely won't work. Keep in mind the div that the background image borders must be expandable. I don't see any way that this can happen without JS or PIE or something else to enable CSS3. Also, please mark this up if we don't find a solution! There are some things that can't be done with CSS alone, and I think we should be aware if this truly is one so that people don't waste their time on it!!!! – Sabrina Leggett Jan 27 '12 at 11:16
  • Don't agree with downvoting this answer. It's a good answer if supporting older browsers is a requirement and more straightforward compared to some css solutions. of course this probably doesn't address window resizing... – craigrs84 Oct 23 '14 at 02:31
-1

There is a really easy fix. Add this to your css display: bock;

Matthew Sprankle
  • 1,626
  • 1
  • 19
  • 26