Bootstrap navbar covers content on zoom

此生再无相见时 提交于 2019-12-06 08:50:55
Christina

This is the way touch devices handle position:fixed: it stays fixed and covers up the rest of the content.

One easy fix is to use the viewport meta tag and disable user scaling:

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />

Some top selling admin themes built with Bootstrap do this. It makes your page behave like an app. However, it screws up users' normal behavior on touch and most developers don't want to screw up accessibility, including Bootstrap's own site "GetBootstrap.com".'

The other is to not use position fixed but use the static position on the navbar. GetBootstrap.com doesn't use a fixed position navbar, it doesn't follow you down the page. On their documentation pages, the affix is working on the sidebar. When you zoom on a touch device the page messes up the layout. This is normal behavior on a touch device. Most of the time, and I've looked into this extensively, the developer has decided to allow accessibility trump layout with respect to zooming on touch, that is: they leave it alone even though it looks bad and covers up content. This is what I'm doing these days.

The other solutions in the @Sebsemilla comment are worth exploring but the one involving media queries is pretty useless. Media queries detect width, height, orientation and pixel density but they do not detect whether or not a person is using a touch device.

Generally, depending on the situation, I detect touch or no-touch with javascript and serve up position:fixed for non-touch devices and position:absolute, or position:static, or position:relative on touch devices. Some people, very few, say something about this but until the fixed position works as you would expect, I think of position:fixed as a progressive enhancement for non-touch devices

Another idea is to fake position fixed with jQuery:

What is the simplest jQuery way to have a 'position:fixed' (always at top) div?

Use it with http://benalman.com/projects/jquery-throttle-debounce-plugin/

Here's a demo I set up: https://jsbin.com/nugibi/2/edit?html,css,js,output

You can combine this with detecting touch and use it only on touch devices.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!