Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    92
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Make a z-indexed div fill its parent

    Hello, I have a page with 3 divs/rows: header, body, and footer. None have a height specified. I also have a div called "overlay". I am trying to get overlay to fill only the body div. Overlay has a z-index and transparency effect.

    I just can't get it to only fill the body div. I has the height of the entire page and causes a vertical scroll bar because it starts below the top of the page. Is this possible without specifying the height of the body div?

    This is my code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Z-index problem</title>
    <style type="text/css">
    	@charset "utf-8";
    	div{
    		overflow:hidden;
    	}
    	
    	body{
    		margin:0px;
    	}
    	#the_header{
    		background:#330099;
    	}
    	#the_body{
    		background:#993300;
    	}
    	#the_overlay{
    		position: absolute;
    		z-index: 1;
    		height: 100%;
    		width: 100%;
    		background-color:#000;
    		filter:alpha(opacity=50);
    		-moz-opacity: 0.50;
    		opacity: 0.50;
    	}
    	#the_footer{
    		background:#99CC33;
    	}
    	
    </style>
    </head>
    <body>
    <div id="the_header">
         <img src="test.gif" style="height:100px; width: 100px;" />
    </div>
    <div id="the_body">
    	<div id="the_overlay">
        </div>
         Testing...<img src="test.gif" style="height:150px; width: 150px;" />
    </div>  
    <div id="the_footer">
    	This is the footer <img src="test.gif" style="height:15px; width: 200px;" />
    </div>
    </body>
    </html>
    Thanks

  • #2
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    Quote Originally Posted by spetsacdc View Post
    I just can't get it to only fill the body div.
    Try this:

    Code:
    	#the_body{
    		background:#993300;
    		position:relative;
    	}
    That should make the underlay div reference its position and percentage dimensions off its parent div (#the_body) and not the browser window.
    matt | design | blog

  • Users who have thanked BoldUlysses for this post:

    spetsacdc (02-20-2009)

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    92
    Thanks
    19
    Thanked 0 Times in 0 Posts
    thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •