<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bloggerrific &#187; css positioning</title>
	<atom:link href="http://www.davidjrush.com/blog/tag/css-positioning/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidjrush.com</link>
	<description>David J. Rush is a web designer and usability consultant in Pittsburgh who freelances and blogs about anything web related.</description>
	<lastBuildDate>Thu, 05 Jan 2012 02:50:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SEO Friendly Two Column Layout</title>
		<link>http://www.davidjrush.com/blog/2011/02/seo-friendly-two-column-layout/</link>
		<comments>http://www.davidjrush.com/blog/2011/02/seo-friendly-two-column-layout/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 14:00:56 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[CSS Tutorials and Tricks]]></category>
		<category><![CDATA[Search Engine Optimization]]></category>
		<category><![CDATA[css positioning]]></category>
		<category><![CDATA[css tricks]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[website layout]]></category>

		<guid isPermaLink="false">http://www.davidjrush.com/?p=908</guid>
		<description><![CDATA[Most website owners, for obvious reasons, want their websites to be highly trafficked. When I build a site for a client, I always make an effort to keep search engine optimization (SEO) in mind so I can help them grow their traffic/clientele/customer base. There are thousands of companies out there claiming they know the secret [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: right; margin: 0px 0px 20px 20px; _margin: 0px 0px 10px 10px;" src="http://www.davidjrush.com/images/tutorials/twoColumnSEO.gif" alt="SEO Friendly Two Column Layout" width="425" height="230" />Most website owners, for obvious reasons, want their websites to be highly trafficked. When I build a site for a client, I always make an effort to keep search engine optimization (SEO) in mind so I can help them grow their traffic/clientele/customer base. There are thousands of companies out there claiming they know the secret to landing you at the top of Google search results, but when it comes down to it, there is no one answer&#8230; there are a lot. One such item to try for your site is keeping the relevant content of your pages at the top of your HTML code. Sometimes this can be difficult for people working on websites that have a multiple column layout with something like navigation or ads on the left and the main relevant content on the right. Now some might say there are simple solutions to this problem involving using float left and right CSS properties for your respective divs that contain each column, but there are some layouts that require a more sophisticated solution, that is much less prone to break regardless of the actual content.</p>
<p>When implementing this for my fulltime employer, <a href="http://collegeprowler.com/" target="_blank">College Prowler</a>, I stumbled upon a genius post by <a href="http://matthewjamestaylor.com/blog/ultimate-2-column-left-menu-pixels.htm" target="_blank">Matthew James Taylor</a> who has a series on <a href="http://matthewjamestaylor.com/blog/ultimate-multi-column-liquid-layouts-em-and-pixel-widths" target="_blank">multi-column liquid layouts</a> that are all cross-browser compatible and SEO friendly in the sense that I speak of above. I adapted it a little bit to account for some specific 10px margins and a specific navigation width of 300px, which you can also adjust. The requirements are quite simple to implement, and here&#8217;s how to do it:</p>
<p><strong>The HTML:</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;mainWrap&quot;&gt;
  &lt;div class=&quot;mainSubWrap&quot;&gt;
    &lt;div class=&quot;mainContentWrap&quot;&gt;
      &lt;div class=&quot;mainContentSubWrap&quot;&gt;&lt;!--All your main content goes in here--&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;navContentWrap&quot;&gt;&lt;!--Nav content goes in here--&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</pre>
<p><strong>The CSS:</strong></p>
<pre class="brush: css; title: ; notranslate">.mainWrap {
  position: relative;
  clear: both;
  float: left;
  width: 100%;
  overflow: hidden;
  margin: 10px 0px;
}
div.mainSubWrap {
  float: left;
  width: 200%;
  position: relative;
  left: 290px;
}
div.mainContentWrap {
  float: right;
  width: 50%;
  position: relative;
  right: 290px;
}
div.mainContentSubWrap {
  margin: 0px 10px 0px 310px;
  position: relative;
  right: 100%;
}
div.navContentWrap {
  float: left;
  width: 290px;
  position: relative;
  right: 290px;
}
</pre>
<p>Basically you end up using relative positioning to move the navigation box over to the left of the main content box, and visa versa, yielding the main content appearing on the right side of your screen, but appearing first in your code. The benefit to this over a simple float is the ability to assign background colors that you want to fill to the bottom of the screen regardless of whether or not the background colored div is the largest in height. It is also pretty much a sure bet that it won&#8217;t break across browsers.</p>
<p>Definitely give it a shot, and if you have any questions, don&#8217;t hesitate to ask!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidjrush.com/blog/2011/02/seo-friendly-two-column-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript: Rollover Dropdown Menus</title>
		<link>http://www.davidjrush.com/blog/2009/08/javascript-rollover-dropdown-menus/</link>
		<comments>http://www.davidjrush.com/blog/2009/08/javascript-rollover-dropdown-menus/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 13:30:32 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Javascript Tutorials]]></category>
		<category><![CDATA[css classes]]></category>
		<category><![CDATA[css positioning]]></category>
		<category><![CDATA[javascript basics]]></category>

		<guid isPermaLink="false">http://www.davidjrush.com/blog/?p=179</guid>
		<description><![CDATA[Up until recently I&#8217;d never implemented a rollover dropdown menu. Then I just decided to build one from scratch for my employer College Prowler to improve upper-level navigation. Basically, with some simple javascript to hide/show the menu and some CSS to style and position it, you&#8217;ve got yourself a simple javascript rollover dropdown menu! The [...]]]></description>
			<content:encoded><![CDATA[<p>Up until recently I&#8217;d never implemented a rollover dropdown menu. Then I just decided to build one from scratch for my employer <a href="http://collegeprowler.com" target="_blank">College Prowler</a> to improve upper-level navigation. Basically, with some simple javascript to hide/show the menu and some CSS to style and position it, you&#8217;ve got yourself a simple javascript rollover dropdown menu! The code follows the example implementation below.</p>
<div class="clear"></div>
<style>
#container{ position: absolute; z-index: 1001; }
a.mainNav{ color: White; font-weight: bold; font-size: 12px; height: 40px; padding: 0px 10px; line-height: 40px; float: left; background-color: #1D3E66; }
a.mainNav:hover{ background-color: #3D6199; color: #AAAAAA; }
a.selectedRollover{ color: White; font-weight: bold; font-size: 12px; height: 40px; padding: 0px 10px; line-height: 40px; float: left; background-color: #3D6199; }
.rolloverMenu{ float:left; padding: 10px 10px 6px 10px; position: absolute; z-index: 1000; background-color: #3D6199; width: 100px; }
.rolloverMenu#mainMenu{ top: 40px; }
.rolloverMenu a{ color: White; font-weight: bold; font-size: 12px; line-height: 20px; }
</style>
<p><script type="text/javascript">
function rolloverMenu(showHide, menu)
{
    var link = 'mainLink';
    if (showHide == 0){
        document.getElementById(menu).style.display = 'none';
        document.getElementById(link).setAttribute('class', 'mainNav');
        document.getElementById(link).setAttribute('className', 'mainNav');
    }
    else{
        document.getElementById(menu).style.display = 'block';
        document.getElementById(link).setAttribute('class', 'selectedRollover');
        document.getElementById(link).setAttribute('className', 'selectedRollover');
    }
}
</script></p>
<div style="float: right; width: 375px; height: 40px; position: static;">
<div id="container">
<a class="mainNav" href="#" id="mainLink" onmouseover="rolloverMenu(1, 'mainMenu');" onmouseout="rolloverMenu(0, 'mainMenu');">Rollover Me</a></p>
<div class="rolloverMenu" id="mainMenu" style="display: none;" onmouseover="rolloverMenu(1, 'mainMenu');" onmouseout="rolloverMenu(0, 'mainMenu');">
<a href="#">Link 1</a><br /> <a href="#">Link 2</a><br /><a href="#">Link 3</a><br /><a href="#">Link 4</a>
</div>
</div>
</div>
<div class="clear"></div>
<p><strong>The Javascript:</strong></p>
<pre class="brush: jscript; title: ; notranslate">function rolloverMenu(showHide, menu)
{
    var link = 'mainLink';
    if (showHide == 0)
    {
        document.getElementById(menu).style.display = 'none';
        document.getElementById(link).setAttribute('class', 'mainNav');
        document.getElementById(link).setAttribute('className', 'mainNav');
    }
    else
    {
        document.getElementById(menu).style.display = 'block';
        document.getElementById(link).setAttribute('class', 'selectedRollover');
        document.getElementById(link).setAttribute('className', 'selectedRollover');
    }
}</pre>
<p>This javascript will either hide or show the menu depending on the location of the cursor. The HTML that calls the javascript has a delay on it as well, but you&#8217;ll see that later. This javascript also changes the class name of the link so that even though your mouse isn&#8217;t technically hovering over that link it will look like it is being hovered over.</p>
<p><strong>The CSS:</strong></p>
<pre class="brush: css; title: ; notranslate">#container{
    position: absolute;
    z-index: 1001;
}
a.mainNav{
    color: White;
    font-weight: bold;
    font-size: 12px;
    height: 40px;
    padding: 0px 10px;
    line-height: 40px;
    float: left;
    background-color: #1D3E66;
}
a.mainNav:hover{
    background-color: #3D6199;
    color: #AAAAAA;
}
a.selectedRollover{
    color: White;
    font-weight: bold;
    font-size: 12px;
    height: 40px;
    padding: 0px 10px;
    line-height: 40px;
    float: left;
    background-color: #3D6199;
}
.rolloverMenu{
    float:left;
    padding: 10px 10px 6px 10px;
    position: absolute;
    z-index: 1000;
    background-color: #3D6199;
    width: 100px;
}
.rolloverMenu#mainMenu{
    top: 40px;
}
.rolloverMenu a{
    color: White;
    font-weight: bold;
    font-size: 12px;
    line-height: 20px;
}</pre>
<p>Change the CSS to fit your own design. I&#8217;ve been very specific in this CSS so that it should be easier for you to identify everything. Note that the #container definition is actually very important for an IE6 bug fix. IE6 has issues with z-index when not combined with absolute positioning. Basically, the parent element of the rollover menu needs to have that specific definition.</p>
<p><strong>Lastly, the HTML:</strong></p>
<pre class="brush: xml; title: ; notranslate">&lt;div id=&quot;container&quot;&gt;
  &lt;a class=&quot;mainNav&quot; href=&quot;#&quot; id=&quot;mainLink&quot; onmouseover=&quot;rolloverMenu(1, 'mainMenu');&quot; onmouseout=&quot;rolloverMenu(0, 'mainMenu');&quot;&gt;Rollover Me&lt;/a&gt;
  &lt;div class=&quot;rolloverMenu&quot; id=&quot;mainMenu&quot; style=&quot;display: none;&quot; onmouseover=&quot;rolloverMenu(1, 'mainMenu');&quot; onmouseout=&quot;rolloverMenu(0, 'mainMenu');&quot;&gt;
    &lt;a href=&quot;#&quot;&gt;Link 1&lt;/a&gt;&lt;br /&gt;
    &lt;a href=&quot;#&quot;&gt;Link 2&lt;/a&gt;&lt;br /&gt;
    &lt;a href=&quot;#&quot;&gt;Link 3&lt;/a&gt;&lt;br /&gt;
    &lt;a href=&quot;#&quot;&gt;Link 4&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;</pre>
<p>And that&#8217;s that! The HTML link calls the javascript which implements a series of CSS rules that will hide or show the menu of your choice! Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidjrush.com/blog/2009/08/javascript-rollover-dropdown-menus/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CSS Positioning and Layout</title>
		<link>http://www.davidjrush.com/blog/2009/03/css-positioning-and-layout/</link>
		<comments>http://www.davidjrush.com/blog/2009/03/css-positioning-and-layout/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 14:00:32 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[CSS Tutorials and Tricks]]></category>
		<category><![CDATA[css basics]]></category>
		<category><![CDATA[css positioning]]></category>
		<category><![CDATA[website layout]]></category>

		<guid isPermaLink="false">http://www.davidjrush.com/blog/?p=18</guid>
		<description><![CDATA[CSS has two primary benefits. One is the ability to easily edit the look and feel (the theme if you will) of your website by changing very little code. This is evidenced by a quick visit to the CSS Zen Garden which has the same HTML code, but uses different style sheets to make it [...]]]></description>
			<content:encoded><![CDATA[<p>CSS has two primary benefits. One is the ability to easily edit the look and feel (the theme if you will) of your website by changing very little code. This is evidenced by a quick visit to the <a href="http://www.csszengarden.com/" target="_blank">CSS Zen Garden</a> which has the same HTML code, but uses different style sheets to make it all look completely different. The second is positioning and layout which allows to easy move different pieces on a page because it doesn&#8217;t ascribe to the rigidity of tables.</p>
<p>However, CSS layout can get a little confusing when you are just starting out. So this article will discuss the different attributes you can assign to tag objects and when each of them is appropriate.</p>
<p><span style="font-size: 18px;"><strong>Position:</strong></span><br />
The position property has 4 possible values of static, absolute, relative, and fixed. Static is essentially the default that lets an element just fall wherever it falls. You&#8217;ll only find yourself defining an element as have a static position if you need to correct for a previous assignment of something else other than static. The fixed value will put an element at an exact location within the browser regardless of scrolling or screen size. The fixed value is always used in conjunction with the top, right, bottom, and left properties which will be discussed after positioning.</p>
<p>The remaining two properties are the more common definitions, and are also always used in conjunction with the top, right, bottom, and left properties. Absolute positioning is used when you want an element to exist at an &#8220;absolute&#8221; location within the page. The only difference between absolute and fixed is that fixed ignores scrolling, whereas absolute does not. So if I wanted the logo of the website I&#8217;m designing to always be located exactly 10 pixels from the top of the window, and 30 pixels from the left (and if I scrolled down the page it would go out of view), then I&#8217;d use the following CSS:</p>
<pre class="brush: css; title: ; notranslate">img#logo{
   position: absolute;
   top: 10px;
   left: 30px;
}</pre>
<p>I personally think that absolute positioning is a bad idea because it leaves you with something almost as rigid as a table. To move something around you have to constantly adjust pixel positions, and use z-index in case objects overlap. This can sometimes be useful so you don&#8217;t have to layer things using background images with multiple divs, but in general, I personally choose to avoid it. Then there is the relative value. Relative positioning is exactly what it sounds like, it positions an element relative to where it should be located. So if an element naturally falls at a certain location, and you give it a &#8220;top: 10px;&#8221; and &#8220;right: 30px;&#8221; then it will appear 10 pixels further down, and 30 pixels left of that certain location. This is also occassionally useful, but I personally prefer another option&#8230; floating. This I&#8217;ll discuss soon.</p>
<p><span style="font-size: 18px;"><strong>Top, Right, Bottom, Left:</strong></span><br />
These four properties are used when a position of fixed, absolute, or relative has been assigned to the same element (such as a div or an img). These positions can be set using pixels or any other length measurement that CSS accepts, as well as %. They can also have negative values which is helpful to push things around when you need to. Again, I however personally prefer floating my elements.</p>
<p><span style="font-size: 18px;"><strong>Float:</strong></span><br />
If you ask me, the float property is the absolute best characteristic of CSS, and it blows position out of the water. Why do I love it so much? Well, I&#8217;ll admit that it can be finicky, but once you get used to how it works, it is absolutely fantastic for building very fluid designs that you can easily change. Float only has three options, left, right, or none. None is the default value. If you add a &#8220;float: left;&#8221; to your definition then that element will move as far to the left as it can, meaning within its own parent element. Giving is a &#8220;float: right;&#8221; will do the same thing but obviously to the right instead. Check out the example below of two divs, one floating left, and one floating right:</p>
<p><strong>The HTML:</strong></p>
<pre class="brush: xml; title: ; notranslate">&lt;div style=&quot;float: left; width: 150px; border: solid 3px #444444; padding: 5px;&quot;&gt;
  This div will float left
&lt;/div&gt;
&lt;div style=&quot;float: right; width: 150px; border: solid 3px #444444; padding: 5px;&quot;&gt;
  This div will float right
&lt;/div&gt;</pre>
<p><strong>And the outcome:</strong></p>
<div class="example">
<div style="border: 3px solid #444444; padding: 5px; width: 150px; float: left;">This div will float left</div>
<div style="border: 3px solid #444444; padding: 5px; width: 150px; float: right;">This div will float right</div>
</div>
<p>So now that you see how the float works, you might be able to see why it can be so helpful. Imagine just having to change two words in your CSS file, and those two divs would switch locations. Now the reason it can get finicky is because of space issues. An element will float within its parent element as high up as it possibly can. So that means if I increased the width of those sample divs to more than half the allotted space, then the second div would be forced below the first (but still on the right side). You can apply float to a whole lot of elements, but primarily you&#8217;ll probably be using it with div, img, and p.</p>
<p>More notably, float is used to make text wrap around other elements such as an image. This is incredibly common and incredibly useful. Just apply a float to the image right before the paragraph and the paragraph text will wrap around it. You&#8217;ll probably also want to apply a margin so that the text doesn&#8217;t touch the image though.</p>
<p>Well, good luck with your positioning escapades. Let me know if you have any problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidjrush.com/blog/2009/03/css-positioning-and-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Pros and Cons of Tables</title>
		<link>http://www.davidjrush.com/blog/2009/02/the-pros-and-cons-of-tables/</link>
		<comments>http://www.davidjrush.com/blog/2009/02/the-pros-and-cons-of-tables/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 13:00:00 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[css positioning]]></category>
		<category><![CDATA[learn HTML]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[website layout]]></category>

		<guid isPermaLink="false">http://www.davidjrush.com/blog/?p=19</guid>
		<description><![CDATA[When I started my job as a fulltime web designer, I discovered that my boss used tables for everything. This wasn&#8217;t that surprising considering he is a back end developer as opposed to a front end designer. I of course yelled at him (in my mind so as not to get fired) about how horrible [...]]]></description>
			<content:encoded><![CDATA[<p>When I started my job as a fulltime web designer, I discovered that my boss used tables for everything. This wasn&#8217;t that surprising considering he is a back end developer as opposed to a front end designer. I of course yelled at him (in my mind so as not to get fired) about how horrible tables are. Since then, I&#8217;ve settled more in the middle, and I figured I should offer my two cents on the debate of Tables Versus CSS for layout purposes.</p>
<p>First let&#8217;s take a look at the oh-so-obvious faults of tables, and why these cons are such an issue.</p>
<p><span style="font-weight: bold;">Con 1. Tables are incredibly rigid.</span> Short of moving the content from one cell to another, changing the layout of anything within your table is incredibly difficult. Especially since you won&#8217;t want your layout to look like it uses a table, you&#8217;ll end up with rowspans and colspans everywhere.</p>
<p><span style="font-weight: bold;">Con 2. Table code can get messy. </span>If you use tables for all your layout, then you&#8217;ll end up with nested tables all over the place. The code becomes hard to read, and almost impossible to edit.</p>
<p><span style="font-weight: bold;">Con 3. Tables have different default settings in different browsers.</span> If you want your site to look the same no matter what browser your user is viewing it through, then you&#8217;ll have to go through at set padding, margin, border, et cetera to the values you want them to be. This is a hassle because of all the tags associated with tables. You&#8217;ve got table, tr, th, and td. Mind you, even if you don&#8217;t use tables, you should be setting default CSS values anyway to avoid cross-browser issues.</p>
<p><span style="font-weight: bold;">Con 4. Tables increase the size of your files.</span> That&#8217;s right. Tables just often require more code. Even though the difference in load time for most people is negligable, it is still something to consider.</p>
<p>Alright, and now the benefits of tables, and why it is important to set aside your bias against tables and accept these pros.</p>
<p><span style="font-weight: bold;">Pro 1. Tables can be very helpful for certain design elements.</span> Take rounded corners of any box for example. Though you&#8217;ll need anywhere between 1 and 8 images to make a rounded corner box (1 if the box does not need to expand, 3 if it expands in one direction, and 8 if it expands in two), tables will make the implementation of this a lot easier. Of course, you can use divs for this, but you won&#8217;t need to edit this table, just the content and images inside. Divs can float incorrectly in different browsers, ruining your rounded corner box, but the table won&#8217;t break.</p>
<p><span style="font-weight: bold;">Pro 2. Tables are great when you need to show&#8230; tables.</span> That&#8217;s right, sometimes the best way to display information is in a table, and obviously the best way to implement that in the web is using&#8230; you guessed it, a table!</p>
<p><span style="font-weight: bold;">Pro 3. Tables make certain difficult CSS issues much easier.</span> With tables, you can easily vertically center text, or ensure that two separate sentences of text will always appear next to each other horizontally. Obviously, there are tricks in CSS around this anyway. To vertically center a line of text, you can set the line-height to the same pixel height as the div it is in. So clearly, there is always a way around this problem.</p>
<p>When it comes down to it, every pro or con you find for tables doesn&#8217;t really matter. For every pro, using a little CSS magic, you can work around it. For every con, using a little effort or time can work around it too.</p>
<p>In the end, using floating divs is a much safer route to go for your layout. You can change the location of content very easily, your code will be cleaner, and make more sense logically when reading through it. But don&#8217;t knock down tables. Use tables for your overarching page layout (header, body, footer for example). These things won&#8217;t change as much, so tables are a clean and safe solution. Basically, tables aren&#8217;t 100% evil or amazing. Use them when appropriate, and don&#8217;t overdo it, and you&#8217;ll be just fine.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidjrush.com/blog/2009/02/the-pros-and-cons-of-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS &#8211; Sticky Footer</title>
		<link>http://www.davidjrush.com/blog/2009/01/css-sticky-footer/</link>
		<comments>http://www.davidjrush.com/blog/2009/01/css-sticky-footer/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 15:15:00 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[CSS Tutorials and Tricks]]></category>
		<category><![CDATA[css footer]]></category>
		<category><![CDATA[css positioning]]></category>
		<category><![CDATA[css tricks]]></category>
		<category><![CDATA[sticky footer]]></category>
		<category><![CDATA[website layout]]></category>

		<guid isPermaLink="false">http://www.davidjrush.com/blog/?p=11</guid>
		<description><![CDATA[Almost all websites out there have what is called a footer, or a block at the bottom of the page with quick links. For example, my website has a footer at the bottom of the page if you scroll down with links to major sections of my site. When I was looking into implementing this [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: right; margin: 0px 0px 20px 20px; _margin: 0px 0px 10px 10px;" src="http://www.davidjrush.com/images/tutorials/stickyFooter.gif" alt="Sticky Footer Explanation" width="351" height="251" />Almost all websites out there have what is called a footer, or a block at the bottom of the page with quick links. For example, my website has a footer at the bottom of the page if you scroll down with links to major sections of my site. When I was looking into implementing this on my site, I ran into some problems. On some pages, the content didn&#8217;t fill the whole screen (which also varies with different screen resolutions, so the footer would be in the middle of the screen. Obviously, on pages where the content went past the bottom of the screen, this wouldn&#8217;t be a problem because the footer would be pushed to the bottom. So clearly, I needed a footer that would &#8220;stick&#8221; to the bottom of the screen if the content wouldn&#8217;t push it, but if there was enough content, then it would be below the screen bottom. I searched and searched for solutions, and I found one which I adapted just a little bit into my own implementation (in thanks, here is a link to his site, <a href="http://ryanfait.com/sticky-footer/" target="_blank">ryanfait.com</a>.</p>
<p>Ryan&#8217;s solution was fantastic. However, I did still have some problems with it, probably because of my wrapper div that I used to center my content. So below, I have implemented my fix which I have tested in Firefox 2 and 3, Internet Explorer 6 and 7, Safari, Opera, and Chrome. The footer sticks to the bottom of the screen when content doesn&#8217;t push it that far, but goes to the bottom of the page when content goes below the fold. Below is the CSS and HTML for the footer with a wrapper as well. The sticky footer combined with a wrapper allow you to account for pretty much any <a href="http://www.davidjrush.com/blog/2008/12/screen-resolution-size-matters/"> screen resolution</a>) too, which is fantastic! However, there is just one downside to this sticky footer, you absolutely MUST know the height of your footer. Luckily, there are not many cases where you&#8217;d be putting dynamic content into your footer.</p>
<p><span style="font-weight:bold;">First, the CSS:</span></p>
<pre class="brush: css; title: ; notranslate">html{
   height: 100%;
}
body{
   height: 100%;
}
div.wrapper {
   min-height: 100%;
   height: auto !important;
   height: 100%;
   margin: 0 auto -100px auto;
   /*The -100px mentioned above needs to be the exact height of the footer.*/
}
div.footer{
   height: 100px;
   clear: both;
   position: relative;
}
div.nudge{
   height: 100px;
   clear: both;
}</pre>
<p><span style="font-weight:bold;">And now the HTML:</span></p>
<pre class="brush: xml; title: ; notranslate">&lt;html&gt;
  &lt;body&gt;
    &lt;div class=&quot;wrapper&quot;&gt;
      Your main content goes in here
      &lt;div class=&quot;nudge&quot;&gt;&lt;/div&gt;
      &lt;!--The nudge div should remain empty and makes space for the negative margin assigned above.--&gt;
    &lt;/div&gt;
    &lt;div class=&quot;footer&quot;&gt;
      Your footer content goes in here
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>To see a working example of this footer, obviously you can look on this page (because I have one implemented here), or you can check out this <a href="http://www.davidjrush.com/tutorials/css-sticky-footer-example/" target="_blank">example page</a> that I made.</p>
<p>So yeah, it works pretty simply, though I must stress that every line of that CSS is important. You must declare a 100% height for the two parent elements of html and body (and if you have any other tags between those and the wrapper div, then you need a 100% on that as well). This forces the browser to use the whole screen. The three separate height declarations for the wrapper div are each individually important, including the !important addition. &quot;!important&quot; is a statement which makes that lines declaration take precedence over declarations that come after it. This however does not apply in IE, but that&#8217;s okay, because we want it that way for this Sticky Footer. Then most important is how the margins work. By putting a negative margin of the footer&#8217;s height on the wrapper, we allow whatever comes after the wrapper to overlap with it. The nudge div creates empty space inside the main wrapper so that when the footer overlaps exactly with the wrapper, nothing is blocked out. If you theoretically wanted a margin between the wrapper and the footer then make your negative margin on the wrapper 100px, your footer div would be 70, and give the footer a 30px margin on top. The nudge div would also still be 100px again to make space for the footer and its margin.</p>
<p>As a last suggestion, I usually put another div inside the wrapper div and the footer div, give them both a width of 990px and make them float left. The float with the full width will make sure that nothing (such as padding or a margin) manages to creep outside the edge of the wrapper or footer div. This is a safety precaution, but one that I highly suggest. If you notice a problem when you try to implement the sticky footer, this is the first thing that I would suggest.</p>
<p>UPDATE: A common problem that I&#8217;ve seen people run into when implementing this sticky footer is having trouble making your wrapper div take up a defined amount of space in the browser&#8217;s eyes. Floating (as discussed above), or the <a href="http://www.w3schools.com/css/css_display_visibility.asp" target="_blank">CSS display property</a> help the browser know how big a div physically is. If the browser can&#8217;t figure that out, then the footer won&#8217;t align to the bottom correctly. Either add a float to a div immediately inside the wrapper, or add &quot;display: inline-block;&quot; as a style definition to the wrapper div.</p>
<p>Got any questions? Need help troubleshooting? Critiques are welcomed too! Post a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidjrush.com/blog/2009/01/css-sticky-footer/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

