关于高度自适应的应用
某些时候可能需要用到“高度的自适应”。今天又空,就专门去研究了一下,其实原理很简单。
利用position绝对定位容器,设置其高度的百分比,但要注意同时初始化<html><body>的高度值(一般100%),如以下代码。
html {height:100%; max-height:100%;}
body {height:100%; max-height:100%; overflow: hidden;}
body {height:100%; max-height:100%; overflow: hidden;}
一个简单的示例,可以下载文档查看。
下载: code.html
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>无标题文档</title>
- <style type="text/css">
- * { padding:0; margin:0;}
- html {height:100%; max-height:100%;}
- body {height:100%; max-height:100%; overflow: hidden;}
- .box { position:absolute; top:30px; bottom:15px; overflow:auto; background:#ccc; width:200px;}
- .inner { height:1000px;}
- </style>
- </head>
- <body>
- <div class="box">
- <div class="inner"></div>
- </div>
- </body>
- </html>
在具体的实例应用中,肯定是要牵涉到多个容器,那么就可能需要用到z-index来区分开层级显示。下面是我今天弄出来的一个具体的页面。时间仓促,尚有不足之处,见谅!如果你又兴趣,大可以“另存为”而进行研究。将来肯定是有一番用武之处的。
正好用到这个东西,受教了!
[回复]