手机分两层,如何设置高度。_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:43:06
原创
1505人浏览过

在手机UI里,想布局三个DIV,TOP为上部,FOOTER为下部,op_float_bar在TOP里面的底部,请问这个DIV的高度如何设置?
#top { width:100%; height:???;}


 //上层占整个手机的70%高度
 //上层里的BAR,在上层的底部,占上层的20%
    


 //底层占整个手机的30%高度



回复讨论(解决方案)

楼主不妨学习学习jquery-mobile???

若楼主执意手动设定,可以采用jq

<!DOCTYPE html><html><head><script src="http://www.w3school.com.cn/jquery/jquery-1.11.1.min.js"></script><script type="text/javascript">$(function() {	//获取页面的可视区域高度和宽度	var wHeight=document.documentElement.clientHeight;	var footerH= $("#footer").height();	var newH=wHeight-footerH+"px";	//alert(footerH.height());	$("#top_float_bar").css("height",newH);});  </script></head><body><div id="top" style="background:yellow;">123</div><div id="footer" style="height:300px;width:500px;background:red;"></div></body></html>
登录后复制

代码仅供参考。

抱歉,,修改一下,,,赋值的时候不用加px

<!DOCTYPE html><html><head><script src="http://www.w3school.com.cn/jquery/jquery-1.11.1.min.js"></script><script type="text/javascript">$(function() {	//获取页面的可视区域高度和宽度	var wHeight=document.documentElement.clientHeight;	var footerH= $("#footer").height();	var newH=wHeight-footerH;	//alert(footerH.height());	$("#top").css("height",newH);});  </script></head><body><div id="top" style="background:yellow;">123</div><div id="footer" style="height:300px;width:500px;background:red;"></div></body></html>
登录后复制

<!DOCTYPE HTML><html><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width,      initial-scale=1.0, user-scalable=no" />    <title>高度分三块</title>    <script src="js/jquery-1.9.1.min.js"></script>      <script type="text/javascript">        $(function () {            var dqheight = document.documentElement.clientHeight;            $("#allheight").css("height", dqheight);        })    </script></head><body style="padding:0px; margin:0px;">    <div id="allheight">   <div style="height:70%;">       <div style="height:20%">           这里是top的20%       </div>       这里是50%的内容   </div>    <div style="height:30%;">        这里是底部的30%    </div>          </div></body></html>
登录后复制
登录后复制


就这样就行了,,帮你测试过了

<!DOCTYPE HTML><html><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width,      initial-scale=1.0, user-scalable=no" />    <title>高度分三块</title>    <script src="js/jquery-1.9.1.min.js"></script>      <script type="text/javascript">        $(function () {            var dqheight = document.documentElement.clientHeight;            $("#allheight").css("height", dqheight);        })    </script></head><body style="padding:0px; margin:0px;">    <div id="allheight">   <div style="height:70%;">       <div style="height:20%">           这里是top的20%       </div>       这里是50%的内容   </div>    <div style="height:30%;">        这里是底部的30%    </div>          </div></body></html>
登录后复制
登录后复制


就这样就行了,,帮你测试过了


其它上下两个可以,但20%的底部要跟70%的上部的底部对齐,还不行,现20%是在70%的上面的。

html,body{
    height:100%;margin:0;
    overflow:hiden;
}
#top{
     height:70%
}
#top #top_float_bar{
    height:20%
}
#footer{
    height:30%
}

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号