align divs in center but have 1 div 100%

Discussion in 'CSS' started by web_design_sheffield, Mar 9, 2010.

  1. #1
    hello all

    ive been up for a while now and im shattered but i cant seem to find the answer to this.

    here is my 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>Untitled Document</title>
    <style type="text/css">
    <!--
    #header {
    	position:relative;
    	width:990px;
    	height:100px;
    	z-index:1;
    	left: 0px;
    	top: 0px;
    	background-color: #FF0000;
    }
    #landscape {
    	position:relative;
    	width:100%;
    	height:auto;
    	z-index:2;
    	left: 0px;
    	top: 0px;
    	color: #9C0;
    	background-color: #999900;
    }
    #content {
    	position:relative;
    	width:990px;
    	height:50px;
    	z-index:3;
    	left: 0px;
    	top: 0px;
    	color: #D6D6D6;
    	background-color: #0099FF;
    }
    body {
    	text-align: center;
    }
    -->
    </style>
    </head>
    
    <body>
    
    
    
    
    <div id="header"></div>
    <div id="landscape">
      <p>fdgdsfgdfg<br />
        <br />
        DFS<br />
        G<br />
        DF
        GDF<br />
        DF<br />
        SD<br />
        <br />
        FG<br />
      </p>
    </div>
    <div id="content"></div>
    
    
    
    
    
    
    </body>
    </html>
    HTML:
    i want to get the header and footer in the middle. seems simple but my brains gone to sleep!

    thanks in advance
     
    web_design_sheffield, Mar 9, 2010 IP
  2. BrianM

    BrianM Peon

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this. Works in IE6-8, Firefox, Safari and Chrome.

    <!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>Untitled Document</title>
    <style type="text/css">
    	* {
    		margin:0px;
    		padding:0px;
    	}
    	body {
    		text-align: center;
    	}
    	#container {
    		position: absolute;
    		left: 0;
    		top: 0;
    		width:100%;
    	}
    	#header {
    		width:990px;
    		height:100px;
    		background-color: #FF0000;
    	}
    	#content {
    		width:100%;
    		height:auto;
    		color: #9C0;
    		background-color: #999900;
    	}
    	#footer {
    		width:990px;
    		height:50px;
    		color: #D6D6D6;
    		background-color: #0099FF;
    	}
    	.center {
    		margin-left: auto;
    		margin-right: auto;
    	}
    
    </style>
    </head>
    
    <body>
    <div id="container">
    	<div id="header" class="center"></div>
    	<div id="content">
    		<p>fdgdsfgdfg<br /><br />
    		DFS<br />
    		G<br />
    		DF
    		GDF<br />
    		DF<br />
    		SD<br /><br />
    		FG<br />
    		</p>
    	</div>
    	<div id="footer" class="center">
    	</div>
    </div>
    </body>
    </html>
    Code (markup):
     
    BrianM, Mar 9, 2010 IP