Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make div and child div extend at least the full height of browser window

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?

like image 423
Sabrina Leggett Avatar asked Jan 22 '12 22:01

Sabrina Leggett


People also ask

How do I make my div full height of the browser window?

Syntax: To set a div element height to 100% of the browser window, it can simply use the following property of CSS: height:100vh; Example: HTML.

How do you make a child div take full height of parent div?

Example 2: The second way to achieve this by using align-items property in the parent div to 'stretch'. It makes every . child-div 100% height of it's parent height.

How do I make my kids div full width?

In this case, we set the child element's width to be 100% of the viewport width by using a percentage viewport unit (vw), then, we move it to the left side (by the distance of the viewport's half, minus 50% of the width of the parent element) with the left property.


3 Answers

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.

like image 166
anon-e-mouse Avatar answered Sep 29 '22 16:09

anon-e-mouse


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;
}
like image 34
Shredderroy Avatar answered Sep 29 '22 16:09

Shredderroy


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.

like image 20
Conan Avatar answered Sep 29 '22 18:09

Conan