如何在IE 6中将浮动页脚粘贴到视口的底部?
时间:2020-03-06 14:51:06 来源:igfitidea点击:
我知道可以轻松地通过position:fixed进行操作,但是不幸的是,我坚持支持IE6. 如何做到这一点?我宁愿使用CSS来保持干净,但是如果我必须使用Javascript,那还不是世界的尽头。在我当前的实现中,我有一个"浮动页脚",它浮动在主要内容区域上方,并使用Javascript定位。我现在拥有的实现即使使用Java脚本也不是特别优雅,所以我的问题是:
- 没有Java,有没有办法做到这一点?
- 如果必须使用Javascript,是否有解决此浮动页脚问题的"不错"的解决方案? "好"是指可以在浏览器中使用的东西,不会过载浏览器的资源(因为它必须经常重新计算),并且优雅/易于使用(例如,编写类似
new FloatingFooter之类的东西会很好。 (" floatingDiv")
)。
我猜想没有一个超级简单的解决方案可以满足以上所有需求,但是我可以借鉴的东西会很棒。
最后,只是一个更普遍的问题。我知道这个问题很难解决,那么还有什么其他UI替代方法,而不是在每个页面的底部都有页脚内容?在我的特定站点上,我用它来显示步骤之间的转换。我还有其他方法可以做到这一点吗?
解决方案
我过去使用CSS表达式来完成此操作。
尝试这样的事情:
.footer { position: absolute; top: expression((document.body.clientHeight - myFooterheight) + "px"); }
在这里阅读更多
和这里
如果页脚具有固定的高度,并且我们知道该高度并且可以在CSS中对其进行硬编码,则可以执行以下操作:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <style> .content { position : absolute; top : 0; left : 0; right : 0; bottom : 50px; /* that's the height of the footer */ overflow : auto; background-color : blue; } .footer { position : absolute; left : 0; right : 0; bottom : 0px; /* that's the height of the footer */ height : 50px; overflow : hidden; background-color : green; } </style> </head> <body> <div class="content"> everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here everything from the page goes here </div> <div class="footer"> the footer </div> </body> </html>
这可能对我们有用。对我来说,它可以在IE6和Firefox 2.0.0.17上运行。试一试。为了达到效果,我使页脚的高度很高。我们显然会根据需要进行更改。希望这对我们有用。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Liquid Footer</title> <style type="text/css"> .footer { background-color: #cdcdcd; height: 180px; text-align: center; font-size:10px; color:#CC0000; font-family:Verdana; padding-top: 10px; width: 100%; position:fixed; left: 0px; bottom: 0px; } </style> <!--[if lte IE 6]> <style type="text/css"> body {height:100%; overflow-y:auto;} html {overflow-x:auto; overflow-y:hidden;} * html .footer {position:absolute;} </style> <![endif]--> </head> <body> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> This is to expand the content on the page<br> <div class="footer">-- This is your liquid footer --</div> </body> </html>
如果将"高度"设置为" 100%",并将"溢出:自动"设置为" <html />"和" <body />"标记,则具有绝对位置的所有内容都将变为固定。最基本的原因是滚动条位置奇怪,非常时髦,但是可以调整以得到不错的结果。
例子
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <style> html, body { height: 100%; overflow: auto; } .fixed { position: absolute; bottom: 0px; height: 40px; background: blue; width: 100%; } </style> </head> <body> <div class="fixed"></div> overflow....<br /> overflow....<br /> overflow....<br /> overflow....<br /> overflow....<br /> overflow....<br /> overflow....<br /> overflow....<br /> overflow....<br /><!-- ... --> </body> </html>
如果我们不想使用条件注释,以便可以将CSS放在单独的文件中,请使用!important
。像这样的东西:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <style> html { overflow-x: auto; overflow-y: scroll !important; overflow-y: hidden; /* ie6 value b/c !important ignored */ } body { padding:0; margin:0; height: 100%; overflow-y: hidden !important; overflow-y: scroll; /* ie6 value b/c !important ignored */ } #bottom { background-color:#ddd; position: fixed !important; position: absolute; /* ie6 value b/c !important ignored */ width: 100%; bottom: 0px; z-index: 5; height:100px; } #content { font-size: 50px; } </style> </head> <body> <div id="bottom"> keep this text in the viewport at all times </div> <div id="content"> Let's create enough content to force scroll bar to appear. Then we can ensure this works when content overflows. One quick way to do this is to give this text a large font and throw on some extra line breaks. <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/> </div> </body> </html>