Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS Layout help, no tabes or java script

Status
Not open for further replies.

SteveDingle

Programmer
Jul 26, 2004
254
GB
Heya All,

Still working on non-table CSS layout. I slapped together the following code based on code at Dougls Livingston's site ( which gives me a header, footer and 3 columns. However I'm hoping for a bit more but maybe I'm being to greedy...

I would like the Left, Middle and Right columns to "push" the footer to the bootom of the page regardless of content. I very rarely will have enought text to "fill" a page but don't realy like alot of empty whitespace at the bottom.

My hope is to do this without tables or Javascript (read somewhere else that you shouldn't rely on javascript in case user have turned off)

If not possible. fair enough, but thought I would ask before spending days searching around for something not possible.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
	<title>Untitled</title>

<style type="text/css">

body {
	margin: 0 0;
	padding: 0 0;
}

#ContainerMain {
	border: 1px solid black;
	margin: 0 -1px;
	min-width: 400px;	
	padding: 0 0;
	width: 100%; 
}
#Header{
	background: yellow;
	height: 120px;
	padding: 0 0;
	position: relative;
	width: 100%;	
	z-index: 4;
}
#Footer{
	background: green;
	height: 30px;
	padding: 0 0;
	position: relative;
	width: 100%;	
	z-index: 4;
}

#ContainerColumns {
	border-left-width: 150px;  /* left column width */
	border-left-color: #FFFFC6;   /* left column colour */
	border-left-style: solid; 
	background-color: white; /* center column colour */
	border-right-width: 50px; /* right column width */
	border-right-color: #FFFFC6;  /* right column colour */
	border-right-style: solid; 
	width: auto; 
}
#ContainerInner {
	margin: 0; 
	width: 100%;
}

#ColumnLeft{
	float: left; 
	margin-left: -150px;
	position: relative;
	width: 150px;
	z-index: 1;
}
#ColumnMiddle{
	float: left; 
	position: relative;
	width: 100%;  
	z-index: 3;
}
#ColumnRight{
	float: left; 
	margin-right: -50px;
	position: relative;
	width: 50px;
	z-index: 2;
}
#ColumnClear{
	clear: both;
}
</style>
</head>

<body>
<div id="ContainerMain">
	<div id="Header">
		Header
	</div>
	<div id="ContainerColumns">
		<div id="ContainerInner">
			<div id="ColumnLeft">
				<p>
				Left
				</p>
			</div> <!-- id="ColumnLeft" -->		
			<div id="ColumnMiddle">
				<p>
				Middle
				</p>
			</div> <!-- id="ColumnMiddle" -->		
			<div id="ColumnRight">
				<p>
				Right
				</p>
			</div> <!-- id="ColumnRight" -->		
			<div id="ColumnClear">
			</div> <!-- id="ColumnClear" -->		
		</div> <!-- id="ContainerInner" -->		
	</div> <!-- id="ContainerColumns" -->		
	<div id="Footer">
		Footer
	</div>
</div> <!-- id="ContainerMain" -->
</body>
</html>

Thanks!!!!!!

Toodles,
Steve Dingle
D&S Business Solutions Ltd
 
I don't understand. Shouldn't that design allow you to do just that? Any of the columns would push the footer to the bottom of that column. If you want the footer to reside at the bottom of the page, that just cannot be done without javascript, which would determine the screen size of the user agent. You could paste the footer on the bottom of the page (position it absolutely) but that would cause more problems than solutions. I say you stay with what you got.
 
Vrag-

Have you tried extending, say, the text that says "Left" to maybe "Left Left Left Left Left Left Left"...

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Thanks for the responses

vragabond -

If you want the footer to reside at the bottom of the page, that just cannot be done without javascript

Thats basically what I wanted to know. Guess I'll just have to accept that if I want to have a table-less layout, my site won't look like I want it to if users have javascript turned off. Does seem like a limitation but I guess I have to change my expectations.

cLFlaVA -
maybe "Left Left Left Left Left Left Left"...

Thats making the content change the size. Basically what I was hoping for is what I would do with table..

"psuedo code"

<tr height = "50px" >
Header
</tr>
<tr height = "100%" >
Middle
</tr>
<tr height = "30px" >
Footer
</tr>

Toodles,
Steve Dingle
D&S Business Solutions Ltd
 
Actually, I was lazy and assumed the design made sure it worked. Elements were floated, there was an element that cleared them... code looked ok, I just didn't have the time to test it.
 
SteveDingle-

While your design looks OK in IE, due to the box model hack, you cannot see the border-left and border-right colors in FF, and likely cannot see them in any non-IE browser.

Another note: z-index is relevant only to absolutely-positioned objects. When I removed your z-indexes (all of them) the solution you're trying to get works (in IE only, which is apparently where you've tested it).

Some more CSS work will need to be performed to get this design to be operable in all browsers.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Heya cLFlaVA,

Some more CSS work will need to be performed to get this design to be operable in all browsers.

:) baby steps for me for now, I was actually just previewing in Homesite 5.5.

Thanks for the tips re: z-index. I have to admit I'm not 100% sure what the code is actually doing, my expertise is in database/oop programming.. this is whole new world and often makes me feel quite the idiot

I have found the following layout which is what I'm aiming for... I've got my fingers x'd


thanks again!

Toodles,
Steve Dingle
D&S Business Solutions Ltd
 
While this may seem repetitive and annoying for you, I would suggest you look at this. I know it can be frustrating to start over.

I'm also going to take a few minutes to try to incorporate your design into the mold I've suggested, since I currently have nothing better to do at work.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Here we go. This code looked fine for me. There are only some small changes you'll need to make:

Changes:

1) Make a 150px image for the left column. It needs to be 150px in width, and the height does not matter. Something like 3 px in height should be fine. Make it the correct solid color you had as a border-left originally.

2) Make another image for the right column. It needs to be 50px in width, and again, the height doesn't matter. Make it the color you want your right column to be.

3) Use this code below:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html lang="en"><head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
	
	<title>New Concept...</title><style type="text/css" media="screen">
		
		body
		{
			margin: 0;
			padding: 0;
		}

		div#banner
		{
			background-color: yellow;
			height: 120px;
		}
		
                [red]/* change this path/file to your left column image */[/red]
		div#container
		{
			background-image: url(images/background.png);
			background-repeat: repeat-y;
		}
		
                [red]/* change this path/file to your right column image */[/red]
		div#container2
		{
			background-image: url(images/background.png);
			background-repeat: repeat-y;
			background-position: right;
		}
		
		div#navigation
		{
			float: left;
			width: 150px;
		}
		
		div#more
		{
			float: right;
			width: 50px;
			margin: 0;
			background-image: url(more_base.jpg);
		}
		
		div#content
		{
			margin-left: 190px;
			margin-right: 200px;
		}
		
		#cleardiv
		{
			clear: both;
			height: 1em;
		}
		
		div#footer
		{
			clear: both;
			background-color: green;
			height: 30px;
		}
</style></head>

<body>
<div id="banner">Header</div>
<div id="container">
<div id="container2">
	<div id="navigation">Left</div>
	<div id="more">Right</div>
	<div id="content">
		Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
	</div>
	<div id="cleardiv"></div>
</div>
</div>
<div id="footer">Here is the footer</div>
</body></html>

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Heya cLFlaVA,

Thanks very much for the code! Really do appreciate your time. After a quickie test viewing in IE/Opera/NetScape and I can see evrything. I still need to install FireFox and test it on there

The footer thought still seems to be based on the "content" as opposed to being on the bottom of the "viewing" area, with the columns filling down to it.

I'll use what you have given me as a base and see if I can get it to what I'm looking for.

Thanks again!!!!

Toodles,
Steve Dingle
D&S Business Solutions Ltd
 
ahh i see -

i originally misunterstood your question. Vragabond's original statement is correct - you cannot achieve this without using JavaScript.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
just add a height to each column:
Code:
#ColumnLeft{
    float: left; 
    margin-left: -150px;
    position: relative;
    width: 150px;
    z-index: 1;

    height: 200px /* or whatever height you want */
    }
that works for me.

Also - You can use z-indexing on relatively positioned elements as well as absolute ones. I've done it before.
 
halcrow-

what if the height of my screen is 800? 1000? 1200?

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
SteveDingle -

Here's a JavaScript solution:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html lang="en"><head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    
    <title>New Concept...</title><style type="text/css" media="screen">
        
        body
        {
            margin: 0;
            padding: 0;
        }

        div#banner
        {
            background-color: yellow;
            height: 120px;
        }
        
                /* change this path/file to your left column image */
        div#container
        {
            background-image: url(background.gif);
            background-repeat: repeat-y;
        }
        
                /* change this path/file to your right column image */
        div#container2
        {
            background-image: url(background.gif);
            background-repeat: repeat-y;
            background-position: right;
        }
        
        div#navigation
        {
            float: left;
            width: 150px;
        }
        
        div#more
        {
            float: right;
            width: 50px;
            margin: 0;
            background-image: url(more_base.jpg);
        }
        
        div#content
        {
            margin-left: 190px;
            margin-right: 200px;
        }
        
        #cleardiv
        {
            clear: both;
            height: 1em;
        }
        
        div#footer
        {
            clear: both;
            background-color: green;
            height: 30px;
        }
</style>

<script language="javascript">
<!--

function resizeBody() {
    // set this to the height of your footer (number only)
	var bottom_height = 30;

	// set this to the height of your header (number only)
	var top_height = 120;

	// maximum height of screen
	var max_height = document.documentElement.clientHeight;

	// div to resize
	var the_div = document.getElementById('container2');

	// set the height
	the_div.style.height = (max_height - (bottom_height + top_height)) + "px";
}

onload = resizeBody;
onresize = resizeBody;
-->
</script>

</head>

<body>
<div id="banner">Header</div>
<div id="container">
<div id="container2">
    <div id="navigation">Left</div>
    <div id="more">Right</div>
    <div id="content">
        Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
    </div>
    <div id="cleardiv"></div>
</div>
</div>
<div id="footer">Here is the footer</div>
</body></html>

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
^ ^ ^fair point, but at least that will pad it out a bit.

Shame height: x% doesn't work...
 
Heya Halcrow,

Thanks for responding but I would have to agree with clFlaVA with the probelm of just setting the height to an arbritray number

However eI did track down the following example which gets me what I want.. almost ;-) Seems to work okay in latest of IE and Opera, for FireFox and Netscape the footer always goes beyond the bottom of the viewing area... but I'm hoping I'm abit closer. FWIW, I found this exmple here:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
	<title>Template 1 - 3 Columns with Header and Footer(at bottom)</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<style type="text/css">
	html, body{ 
		height:100%; 
	} 
	body {
			background: silver;  /* url(leftcolbg.jpg) repeat-y left top */
			color: black;
			padding:0;
			margin:0;
	}
	#ContainerMain {
   	background: white;
		border-left:1px solid #000;
		border-right:1px solid #000;
		color: black;
		height:100%;
		margin-left:130px; /* Same width as Left Column */
		margin-right:130px; /* Same width as Right Column */
		margin-bottom:-52px; /* Same as Footer Height + 2, negative */
		min-height:100%;
	}
	html>body #ContainerMain{ /*for mozilla as IE treats height as min-height anyway*/
		height:auto;
	} 
	#Header{
		background: navy;
		border-bottom:1px solid #000;
		border-top:1px solid #000;
		color: white;
		height: 70px;
		left: 0;
		overflow:hidden;
		position: absolute;
		text-align: center;
		top: 0;
		width: 100%;	
	}
	#ColumnLeft{
		float: left; 
		margin-left: -129px; /*must be 1px less than width otherwise won't push footer down */
		position: relative; /*ie needs this to show float */
		text-align: center;
		width: 130px;
	}
	* html #ColumnLeft {
		margin-right:-3px;
		padding-bottom:52px ; /* Same as Footer Height + 2*/
	}/*fix gap in ie next to float and clear footer because we've moved float too far left*/
	#ColumnRight{
		float: right; 
		margin-right: -129px; /*must be 1px less than width otherwise won't push footer down */
		position: relative; /*ie needs this to show float */
		text-align: center;
		width: 130px; 
	}
	* html #ColumnRight { /* stop float drop in ie */
		margin-right:-130px; /* same as column right width , negative*/
		padding-bottom:52px ; /* Same as Footer Height + 2*/
	}
	#Footer{
		background-color: maroon;
		border-bottom:1px solid black;
		border-top:1px solid black;
		clear: both;
		color: white;
		height: 50px;
		position: relative;
		text-align: center;
		width: 100%;	
	}
	/* Was in example so left ere but not sure what it does*/
	* html #Footer {/*only ie gets this style*/
		\height:52px;/* for ie5 */
		he\ight:50px;/* for ie6 */
	}
  	#ClearForHeader{ /*needed to make room for header*/
		height:72px; /* Same as Header Height + 2*/ 
	}
  	#ClearForFooter{ /*needed to make room for footer*/
		clear:both;
		height:50px; /* Same as Footer Height*/
	}
	* > html #ClearForFooter {
		float:left;
		width:100%;
	}
	div,p  { /*clear top margin for mozilla*/
		margin-top:0
	}
	* html #ColumnCenter { /* combat IE's 3 pixel jog */
		height:1%;
		margin-bottom:12px;
	}
	#ColumnCenter{
		float: right; 
		position: relative;
		margin: 0 -0.5%; /* Important though not sure what */
		text-align: center;
		width: 100%;  
	}
	#ClearLeftCenter{
		clear: both;
		 }

	#ContainerInner {
		float: left;
		width: 99%;
	}

	</style>
</head>

<body>

<div id="ContainerMain">

   <div id="ClearForHeader"></div>

	<div id="ContainerInner">

		<div id="ColumnCenter">
			<p>Center</p>
		</div> <!-- id="ColumnCenter" -->		

		<div id="ColumnLeft">
			<p><h3>Left</h3></p>		
		</div> <!-- id="ColumnLeft" -->		

		<div style="clear:both"></div>

	</div> <!-- id="ContainerInner" -->		

	<div id="ColumnRight">
		<p>Right</p>
	</div> <!-- id="ColumnRight" -->		

	<div id="ClearLeftCenter"></div>

</div> <!-- id="ContainerMain" -->

<div id="Footer">
	<h3>Footer</h3>
</div> <!-- id="Footer" -->

<div id="Header">
	<h1>Header</h1>
</div> <!-- id="Header" -->

</body>
</html>

Thanks again all!

Toodles,
Steve Dingle
D&S Business Solutions Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top