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


发布者 蔚蓝天空  发布时间 1619406447092
关键字 编程技巧 

  Html5移动端div固定到底部实现底部导航条的几种方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  需求:

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

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

  html结构如下:

  滚动区域

  底部固定菜单

  方法一:使用fixed

  .box{

  .roll{

  padding-bottom:1rem;

  }

  footer{

  position:fixed;bottom:0;z-index:999;

  }

  }

  方法二:使用absolute

  .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;

  }

  }

  方法三:使用flex

  .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;

  }

  }

  总结

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

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

  ios:激活输入框时,底部不会弹出来(合理)。

  Android:激活输入框时,底部会跟着输入框弹出来(不合理)

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

  3、使用方法二或者方法三,需要设置-webkit-overflow-scrolling 属性。这样才能保证滚动区域的流畅性,-webkit-overflow-scrolling控制元素在移动设备上是否使用滚动回弹效果。

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

  ::-webkit-scrollbar{//scroll滚动条设置

  width: 0px; height: 0px; color: rgb(136, 0, 0);">#fff;

  }

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

dribbble.com/uiwea/collections/4691664
dribbble.com/nbdie/collections/4691723
dribbble.com/nbdie/collections/4691722
dribbble.com/nbdie/collections/4691720
dribbble.com/nbdie/collections/4691719
dribbble.com/nbdie/collections/4691718
dribbble.com/nbdie/collections/4691717
dribbble.com/nbdie/collections/4691714
dribbble.com/nbdie/collections/4691713
dribbble.com/nbdie/collections/4691711
dribbble.com/nbdie/collections/4691710
dribbble.com/nbdie/collections/4691709
dribbble.com/nbdie/collections/4691706
dribbble.com/uicle/collections/4691759
dribbble.com/uicle/collections/4691756
dribbble.com/uicle/collections/4691754
dribbble.com/uicle/collections/4691753
dribbble.com/uicle/collections/4691751
dribbble.com/uicle/collections/4691750
dribbble.com/uicle/collections/4691748
dribbble.com/uicle/collections/4691747
dribbble.com/uicle/collections/4691746
dribbble.com/uicle/collections/4691744
dribbble.com/aeuni/collections/4693270
dribbble.com/aeuni/collections/4693251
dribbble.com/aeuni/collections/4693237
dribbble.com/aeuni/collections/4693217
dribbble.com/aeuni/collections/4693202
dribbble.com/aeuni/collections/4693186
dribbble.com/aeuni/collections/4693167
dribbble.com/aeuni/collections/4693152
dribbble.com/aeuni/collections/4693133
dribbble.com/aeuni/collections/4693115
dribbble.com/nviya/collections/4693717
dribbble.com/nviya/collections/4693698
dribbble.com/nviya/collections/4693671
dribbble.com/nviya/collections/4693648
dribbble.com/nviya/collections/4693612
dribbble.com/nviya/collections/4693595
dribbble.com/nviya/collections/4693567
dribbble.com/nviya/collections/4693547
dribbble.com/nviya/collections/4693507
dribbble.com/nviya/collections/4693473
dribbble.com/caieyc/collections/4694187
dribbble.com/caieyc/collections/4694171
dribbble.com/caieyc/collections/4694151
dribbble.com/caieyc/collections/4694134
dribbble.com/caieyc/collections/4694113
dribbble.com/caieyc/collections/4694093
dribbble.com/caieyc/collections/4694067
dribbble.com/caieyc/collections/4694047
dribbble.com/caieyc/collections/4694024
dribbble.com/caieyc/collections/4693996
dribbble.com/caieyc/collections/4693980
dribbble.com/caieyc/collections/4693963
dribbble.com/liuec/collections/4694617
dribbble.com/liuec/collections/4694604
dribbble.com/liuec/collections/4694583
dribbble.com/liuec/collections/4694562
dribbble.com/liuec/collections/4694545
dribbble.com/liuec/collections/4694532
dribbble.com/liuec/collections/4694523
dribbble.com/liuec/collections/4694507
dribbble.com/liuec/collections/4694491
dribbble.com/liuec/collections/4694470
dribbble.com/liuec/collections/4694451
dribbble.com/liuec/collections/4694433
dribbble.com/liuec/collections/4694421
dribbble.com/nueabu/collections/4694993
dribbble.com/nueabu/collections/4694980
dribbble.com/nueabu/collections/4694963
dribbble.com/nueabu/collections/4694947
dribbble.com/nueabu/collections/4694934
dribbble.com/nueabu/collections/4694929
dribbble.com/nueabu/collections/4694922
dribbble.com/nueabu/collections/4694908
dribbble.com/nueabu/collections/4694896
dribbble.com/nueabu/collections/4694879
dribbble.com/nueabu/collections/4694863
dribbble.com/nueabu/collections/4694847
dribbble.com/nyuie/collections/4695326
dribbble.com/nyuie/collections/4695310
dribbble.com/nyuie/collections/4695296
dribbble.com/nyuie/collections/4695277
dribbble.com/nyuie/collections/4695262
dribbble.com/nyuie/collections/4695248
dribbble.com/nyuie/collections/4695234
dribbble.com/nyuie/collections/4695220
dribbble.com/nyuie/collections/4695207
dribbble.com/nyuie/collections/4695191
dribbble.com/nyuie/collections/4695176
dribbble.com/nyuie/collections/4695161
dribbble.com/neisda/collections/4645232
dribbble.com/neisda/collections/4645230
dribbble.com/neisda/collections/4645227
dribbble.com/neisda/collections/4645225
dribbble.com/neisda/collections/4645221
dribbble.com/neisda/collections/4645220
dribbble.com/neisda/collections/4645216
dribbble.com/neisda/collections/4645215
dribbble.com/neisda/collections/4645213
dribbble.com/dfafae/collections/4641926
dribbble.com/dfafae/collections/4641930
dribbble.com/dfafae/collections/4641932
dribbble.com/dfafae/collections/4641936
dribbble.com/dfafae/collections/4641939
dribbble.com/dfafae/collections/4641942
dribbble.com/dfafae/collections/4641945
dribbble.com/dfafae/collections/4641948
dribbble.com/dfafae/collections/4641949
dribbble.com/dfafae/collections/4641950
dribbble.com/kjsdfei/collections/4652056
dribbble.com/kjsdfei/collections/4652042
dribbble.com/kjsdfei/collections/4652025
dribbble.com/kjsdfei/collections/4652008
dribbble.com/kjsdfei/collections/4651994
dribbble.com/kjsdfei/collections/4651979
dribbble.com/kjsdfei/collections/4651962
dribbble.com/kjsdfei/collections/4651949
dribbble.com/kjsdfei/collections/4651940
dribbble.com/kjsdfei/collections/4651927
szxy.doodlekit.com/
hzdh.doodlekit.com/
shxyba.doodlekit.com/
cdxye.doodlekit.com/
dribbble.com/cauio/collections/4652271
dribbble.com/cauio/collections/4652266
dribbble.com/cauio/collections/4652262
dribbble.com/cauio/collections/4652254
dribbble.com/cauio/collections/4652248
dribbble.com/cauio/collections/4652238
dribbble.com/cauio/collections/4652232
dribbble.com/cauio/collections/4652227
dribbble.com/cauio/collections/4652220
dribbble.com/cauio/collections/4652208
dribbble.com/nainw/collections/4652443
dribbble.com/nainw/collections/4652440
dribbble.com/nainw/collections/4652434
dribbble.com/nainw/collections/4652426
dribbble.com/nainw/collections/4652420
dribbble.com/nainw/collections/4652415
dribbble.com/nainw/collections/4652405
dribbble.com/nainw/collections/4652399
dribbble.com/nainw/collections/4652393
dribbble.com/nainw/collections/4652384
dribbble.com/nainw/collections/4652379
dribbble.com/nainw/collections/4652372









  开源的 OurJS
OurJS开源博客已经迁移到 OnceOA 平台。

  关注我们
扫一扫即可关注我们:
OnceJS

OnceOA