|
|
|
![]() |
div id="wrap" div id="header" Header goes here /div (header) div id="main" class="clearfix" ... Main goes here (this is where we put our three-column layout) ... /div (main) /div (wrap) div id="footer" Footer goes here /div (footer) |
|
html, body, #wrap {height: 100%;} body > #wrap {height: auto; min-height: 100%;} #main {padding-bottom: 150px;} /* must be same height as the footer */ #footer {position: relative;margin-top: -150px; height: 150px;clear:both;} .clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; } .clearfix {display: inline-block;} /*seen by all browsers, fixes IE Mac*/ /* Hides from IE-mac \*/ * html .clearfix { height: 1%;}/*hidden from IE Mac, seen by all other browsers*/ .clearfix {display: block;} /*and resets display to block*/ /* End hide from IE-mac */ |
1) html, body wrap tags height:100%; //takes the whole screen 2) body > #wrap This is only for "wrap" division under "body"
height: auto; min-height:100%;
|
|
In the CSS code we specify that footer has the height of 150 pixels and "margin-top" property equal to -150 pixels, which will raise the header's content exactly 150 pixels above its default position. The clear:both property discourages other elements from attempting to float to either side of the footer. The relative positioning of the footer positions it relative to its normal position, which is right after the "wrap", and "wrap" is defined to have the height of 100% of the window.
|
|
|
html, body, #wrap {height: 100%;} body > #wrap {height: auto; min-height: 100%;} #main {padding-bottom: 150px;} /* must be same height as the footer */ #footer {position: relative;margin-top: -150px; height: 150px;clear:both;} .clearfix:after { content: " "; display: block; font-size: 0; height: 0; clear: both; visibility: hidden; } .clearfix {display: inline-block;} /* Hides from IE-mac \*/ html .clearfix { height: 1%;} .clearfix {display: block;} /* End hide from IE-mac */ |
|
HTML code for multi-column layout with clearfix hackhtml head title /title style type=text/css /style /head body div id="wrap" div id="header" Header goes here /div (header) ... div id="main" class="colmask threecol clearfix" div class="colmid" div class="colleft" div class="col1" Column 1 goes here /div div class="col2" Column 2 goes here /div div class="col3" Column 3 goes here /div /div (colleft) /div (colmid) ... /div (main colmask threecol clearfix) /div (wrap) div id="footer" Footer goes here /div (footer) /body /html CSS code for clearfix hackhtml, body, #wrap {height: 100%;} body > #wrap {height: auto; min-height: 100%;} #main {padding-bottom: 150px;} /* must be same height as the footer */ #footer {position: relative;margin-top: -150px; height: 150px;clear:both;} .clearfix:after { content: " "; display: block; font-size:0; height: 0; clear: both; visibility: hidden; } .clearfix {display: inline-block;} /*seen by all browsers, fixes IE Mac*/ /* Hides from IE-mac \*/ html .clearfix { height: 1%;}/*hidden from IE Mac, seen by all other browsers*/ .clearfix {display: block;} /*and resets display to block*/ /* End hide from IE-mac */ CSS code for three-column layout:body {margin:0; padding:0; border:0; background:#fff; width:100%; min- width:600px; font-size:90%;} a {color:#369;} a:hover {color:#fff; background:#369; text-decoration:none;} h1, h2, h3 {margin:.8em 0 .2em 0; padding:0; } p {margin:.4em 0 .8em 0; padding:0; } img {margin:10px 0 5px;} #header { clear:both; float:left; width:100%; } #header { border-bottom:1px solid #000; } #header p,#header h1, #header h2 {padding:.4em 15px 0 15px; margin:0; } #header ul {clear:left; float:left; width:100%; list-style:none; margin:10px 0 0 0; padding:0; } #header ul li {display:inline; list-style:none; margin:0; padding:0;} #header ul li a { display:block;float:left; margin:0 0 0 1px; padding:3px 10px;text-align:center; background:#eee; color:#000; text-decoration:none; position:relative; left:15px; line-height:1.3em; } #header ul li a:hover { background:#369; color:#fff; } #header ul li a.active, #header ul li a.active:hover {color:#fff; background:#000; font-weight:bold;} #header ul li a span {display:block;} #layoutdims { clear:both; background:#eee; border-top:4px solid #000; margin:0; padding:6px 15px !important; text-align:right; } .colmask {position:relative;clear:both; float:left;width:100%;overflow:hidden;} .colright, .colmid, .colleft {float:left; width:100%; position:relative;} .col1,.col2,.col3 {float:left; position:relative;padding:0 0 1em 0; overflow:hidden; } .threecol { background:#eee;} .threecol .colmid { right:25%; background:#fff;} .threecol .colleft { right:50%; background:#f4f4f4; } .threecol .col1 {width:46%; left:102%;} .threecol .col2 {width:21%; left:31%; } .threecol .col3 { width:21%; left:85%; } #footer { clear:both; float:left; width:100%; border-top:1px solid #000; } #footer p {padding:10px; margin:0; } |
CSS code for clearfix hack1) html, body wrap tags height:100%; //takes the whole screen 2) body > #wrap This is only for "wrap" division under "body"
height: auto; min-height:100%;
CSS code for three-column layout1) body tag border:0; //This removes the border around the viewport in old versions of IE min-width:600px; //Minimum width of layout - remove this line if not required Note that the min-width property does not work in old versions of Internet Explorer 2) layoutdims This is 'widths' sub menu padding:6px 15px !important; 3) .colmask This is column container position:relative; /* This fixes the IE7 overflow hidden bug */ width:100%; /* width of whole page */ overflow:hidden; /* This chops off any overhanging divs */ 4) colright,colmid,colleft Here we declare the common column settings width:100% /* width of page */ 5) col1,col2,col3 /* no left and right padding on columns, we just make them narrower instead only padding top and bottom is included here, make it whatever value you need */ 6) .threecol background:#eee; /* right column background colour */ 7) .threecol .colmid right:25%; /* width of the right column */ background:#fff; /* center column background colour */ 8) .threecol .colleft right:50%; /* width of the middle column */ background:#f4f4f4; /* left column background colour */ 9) .threecol .col1 width:46%; /* width of center column content (column width minus padding on either side) */ left:102%; /* 100% plus left padding of center column */ 10) .threecol .col2 width:21%; /* Width of left column content (column width minus padding on either side) */ left:31%; /* width of (right column) plus (center column left and right padding) plus (left column left padding) */ 11) .threecol .col3 width:21%; /* Width of right column content (column width minus padding on either side) */ left:85%; /* Please make note of the brackets here:*/ /* (100% - left column width) plus (center column left and right padding) plus (left column left and right padding) plus (right column left padding) */ |