Picnic Website Code Tutorials

JS Float Pusher - Sand Bagging Tutorial

View Demo

How do you get a float to remain aligned to the bottom of a container regardless of the containers height? You use javascript that's how! Little or a lot of content, large or small height on the container, no problem! As long as JS is enabled, the float is glued to the bottom of the container. It's a very cool script!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Float Pusher!</title>
<style type="text/css">
body {
background:#666;
}
#wrapper {
margin:auto;
border:1px solid #000;
width:800px;
overflow:hidden;
background:#ccc;
}
p {
margin:10px 10px 0;
text-align:justify;
}
#float {
float:right;
clear:right;
margin:19px 10px 10px; /* margin-top as default line-height to avoid overlap */
border:1px solid #000;
width:200px;
height:100px;
background:#999;
}
.floatpush {
float:right;
margin-bottom:-129px; /* the float height + margin = float to bottom */
width:1px;
}
</style>
<script type="text/javascript">
function a(){var C=document.getElementsByTagName("div"),A=C.length,D,B;for(B=0;B<A;B+=1){D=C[B];if(D.className.indexOf("floatpush")>-1){D.style.height="auto";D.style.height=D.parentNode.offsetHeight+"px"}}}window.onresize=a;window.onload=a;
</script>
</head><body>

<div id="wrapper">
<div class="floatpush"></div>
<div id="float"></div>
<p>Lorem ipsum dolor sit amet consectetuer odio pellentesque scelerisque nisl In. Wisi Vestibulum interdum laoreet pulvinar Curabitur ipsum interdum laoreet adipiscing tincidunt. Nam id platea dolor felis malesuada Nulla cursus magna pretium metus. Orci congue orci feugiat scelerisque malesuada leo vitae Morbi congue ut. Vestibulum Curabitur id id Curabitur vel mi vel vel Suspendisse pretium.</p>
<p>Lorem ipsum dolor sit amet consectetuer odio pellentesque scelerisque nisl In. Wisi Vestibulum interdum laoreet pulvinar Curabitur ipsum interdum laoreet adipiscing tincidunt. Nam id platea dolor felis malesuada Nulla cursus magna pretium metus. Orci congue orci feugiat scelerisque malesuada leo vitae Morbi congue ut. Vestibulum Curabitur id id Curabitur vel mi vel vel Suspendisse pretium.</p>
<p>Lorem ipsum dolor sit amet consectetuer odio pellentesque scelerisque nisl In. Wisi Vestibulum interdum laoreet pulvinar Curabitur ipsum interdum laoreet adipiscing tincidunt. Nam id platea dolor felis malesuada Nulla cursus magna pretium metus. Orci congue orci feugiat scelerisque malesuada leo vitae Morbi congue ut. Vestibulum Curabitur id id Curabitur vel mi vel vel Suspendisse pretium.</p>
<p>Lorem ipsum dolor sit amet consectetuer odio pellentesque scelerisque nisl In. Wisi Vestibulum interdum laoreet pulvinar Curabitur ipsum interdum laoreet adipiscing tincidunt. Nam id platea dolor felis malesuada Nulla cursus magna pretium metus. Orci congue orci feugiat scelerisque malesuada leo vitae Morbi congue ut. Vestibulum Curabitur id id Curabitur vel mi vel vel Suspendisse pretium.</p>
</div>
 
</body></html>
		

Need help adding this or other code to your website? Post it here in the forum! Forum

Sponsors

Top Donators

Friends of Mine