除非内容超出视口范围,否则会粘在视口底部的页脚
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了除非内容超出视口范围,否则会粘在视口底部的页脚相关的知识,希望对你有一定的参考价值。
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> <style media="screen" type="text/css"> html, body { margin:0; padding:0; height:100%; } #container { min-height:100%; position:relative; } #header { background:#ff0; padding:10px; } #body { padding:10px; padding-bottom:60px; /* Height of the footer */ } #footer { position:absolute; bottom:0; width:100%; height:60px; /* Height of the footer */ background:#6cf; } /* other non-essential CSS */ #header p, #header h1 { margin:0; padding:10px 0 0 10px; } #footer p { margin:0; padding:10px; } </style> <!--[if lt IE 7]> <style media="screen" type="text/css"> #container { height:100%; } </style> <![endif]--> </head> <body> <div id="container"> <div id="header"> <!-- Header start --> <!-- Header end --> </div> <div id="body"> <!-- Body start --> <p>In this demo the footer is pushed to the bottom of the screen in all standards compliant web browsers even when there is only a small amount of content on the page. This with work with IE 6 and IE 5.5 too. Non-standards compliant browsers degrade gracefully by positioning the footer under the content as per normal. Read the <a href="http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page">full article</a> for all the details.</p> <!-- Body end --> </div> <div id="footer"> <!-- Footer start --> <!-- Footer end --> </div> </div> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> </body> </html>
以上是关于除非内容超出视口范围,否则会粘在视口底部的页脚的主要内容,如果未能解决你的问题,请参考以下文章
如何强制 div 位于视口的顶部/底部,同时不将其从文档流中取出?