京东6.18大促主会场领京享红包更优惠

 找回密码
 立即注册

QQ登录

只需一步,快速开始

Html5移动端div固定到底部实现底部导航条的几种方式

2024-11-2 22:25| 发布者: db4d5a85| 查看: 116| 评论: 0

摘要: 需求: 需要把导航固定在底部?只能滑动内容,导航菜单固定不动的。效果如下: 这篇文章紧张解说三种实现方案,包括:fixed,absolute,以及css3的flex布局。 html布局如下: [code] <div class="box"> <div cla

需求:

需要把导航固定在底部?只能滑动内容,导航菜单固定不动的。效果如下:

这篇文章紧张解说三种实现方案,包括:fixed,absolute,以及css3的flex布局。

html布局如下:

[code] <div class="box"> <div class="roll">滚动区域</div> <footer>底部固定菜单</footer> </div> <!---公用样式---> <style> html,body{ margin:0;padding:0;height:100%;width:100%; } footer{ background:#F2F3F6;max-width: 750px;width: 100%;height: 1rem; } </style>[/code]

方法一:使用fixed

[code] .box{ .roll{ padding-bottom:1rem; } footer{ position:fixed;bottom:0;z-index:999; } }[/code]

方法二:使用absolute  

[code] .box{ position: relative;height: 100%; .roll{ position: absolute;bottom:1rem;top: 0;overflow-y: scroll;-webkit-overflow-scrolling: touch;height: auto; } footer{ position: absolute;bottom:0; } }[/code]

方法三:使用flex 

[code] .box{ display:flex;display: -webkit-flex;height:100%;flex-direction:column; .roll{ flex: 1; width: 100%;overflow-y: scroll;-webkit-overflow-scrolling: touch;height: auto; } }[/code]

总结

1、底部定位为fixed或absolute的时候,出现优先级别较低,导致被其他div覆盖的环境,那么这里就需要用到z-index,来让他成为最高级别,不至于被覆盖。

2、底部定位为fixed或absolute,存在输入框的时候,会出现如下环境:

[code]ios:激活输入框时,底部不会弹出来(公道)。 Android:激活输入框时,底部会跟着输入框弹出来(不公道)  [/code]

传统办理办法:通常将底部设置为fixed,当激活输入框的时候,将底部定位改为relative,即可兼容ios和Android。

3、使用方法二大概方法三,需要设置-webkit-overflow-scrolling 属性。如许才能包管滚动区域的流畅性,-webkit-overflow-scrolling控制元素在移动设备上是否使用滚动回弹效果。

4、在部门浏览器中设置overflow-y: scroll;会出现滚动条,这时候我们需要全局定义如下样式:

[code] ::-webkit-scrollbar{//scroll滚动条设置 width: 0px; height: 0px; color: rgb(136, 0, 0);">#fff; }[/code]

5、移动端推荐使用方法三的布局形式。

到此这篇关于Html5移动端div固定到底部实现底部导航条的几种方式的文章就先容到这了,更多相干Html5底部导航条内容请搜刮脚本之家以前的文章或继承浏览下面的相干文章,希望大家以后多多支持脚本之家!


来源:https://www.jb51.net/html5/766833.html
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
关闭

站长推荐上一条 /6 下一条

QQ|手机版|小黑屋|梦想之都-俊月星空 ( 粤ICP备18056059号 )|网站地图

GMT+8, 2025-7-2 08:29 , Processed in 0.035202 second(s), 18 queries .

Powered by Mxzdjyxk! X3.5

© 2001-2025 Discuz! Team.

返回顶部