html - Positioning causes body to overlap with footer -
i'm sure positioning cannot resolve issue. body , footer comes on top of each other @ end of page. how can make body liquid doesn't overlap footer?
thanks
jsfiddle here.
css
* { margin: 0px; padding: 0px; } div { display: block; } /* --- body ------------------------------------------------ */ #body_block { float: left; width: 100%; background: #eeeeee; /*background-image: url('../images/bg3.jpg');*/ } #body { margin: 0 auto; position: relative; width: 900px; /*background: #bb0099;*/ } #body_title { position: absolute; top: 15px; left: 0px; width: 200px; /*height: 24px;*/ background: #aa99ff; } #body_search { position: absolute; top: 15px; right: 0px; width: 200px; /*height: 24px;*/ background: #aa99ff; } #body_content { position: relative; top: 50px; left: 0px; width: 900px; /*height: 24px;*/ background: #aa99ff; } /* --- footer ---------------------------------------------- */ #footer_block { float: left; width: 100%; /*background: #dddddd;*/ } #footer { margin: 0 auto; position: relative; width: 900px; padding: 15px 0px 15px 0px; /*background: #cc0011;*/ } html
<body> <div id="body_block"> <div id="body"> <div id="body_title"><h1>home</h1></div> <div id="body_search"><h1>search</h1></div> <div id="body_content"> top<br /><br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br />body<br /><br />bottom </div> </div> </div> <div id="footer_block"> <div id="footer">footer</div> </div> </body>
as @davidmillar said, clearing floats on footer solve overlap problem. however, suspect can achieve design want lot more straightforwardly using of design elements intended.
* { margin: 0px; padding: 0px; } #body { background: #eeeeee; margin: 0 auto; position: relative; width: 900px; /*background: #bb0099;*/ } #body_title { float: left; width: 200px; /*height: 24px;*/ background: #1199ff; } #body_search { float: right; width: 200px; /*height: 24px;*/ background: #aa11ee; } #body_content { clear: both; width: 900px; /*height: 24px;*/ background: #aa99ff; } #footer { width: 900px; padding: 15px 0px 15px 0px; background: #cc0011; } to summarize:
divs block default, no need specify- setting margin/padding = 0 on
*apply elements: no need reapply individually. - the
#body_title,#body_searchcan floated left/right keep them want them. - need clear both floats on
#body_contentgoes document flow - no need add
position: relativeunless plan on moving elements around. in document flow (except 2 floats @ top) no need position them.
i removed wrappers body , footer because felt unnecessary, can add them in. :)
check out new fiddle: http://jsfiddle.net/dr82x/
Comments
Post a Comment