禁用移动网络上的水平滚动

Syl*_*lph 52 css mobile-website

我有一个问题,在我的网站的某些手机上出现水平卷轴.我试图把overflow-x:隐藏起来,但它没有用.宽度是自动的,因此它实际上会自动调整网页大小以适合屏幕大小.所有其他手机都很好,除非在黑莓,诺基亚e52和Windows手机上观看,水平滚动会出现.

有什么建议?谢谢!

pol*_*1er 35

只需添加此CSS:

html, body {
  overflow-x: hidden;
}
body {
  position: relative
}
Run Code Online (Sandbox Code Playgroud)

  • 这是唯一一个适合我的人!谢谢! (2认同)
  • 是最佳答案,将其放入媒体查询中以避免移动设备上的溢出,当然还有媒体视口. (2认同)

Kla*_*eij 25

在stackoverflow上找到了这个答案,这对我来说非常有用:

在风格中使用它

body {
    overflow-x: hidden;
    width: 100%;
}
Run Code Online (Sandbox Code Playgroud)

在head标签中使用它

<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Run Code Online (Sandbox Code Playgroud)

如果您的身体有填充物(为了防止设备缩放到身体内容盒,因此仍然添加水平滚动条),稍微添加我的:

body {
    overflow-x: hidden;
    width: 100%;
    -webkit-box-sizing: border-box;
       -moz-box-sizing: border-box;
            box-sizing: border-box;
}
Run Code Online (Sandbox Code Playgroud)

  • 如果你制作一个应用程序并通过webview查看它,添加它只是为了阻止它从左向右滚动是有帮助的.overflow-x:hidden; (2认同)

小智 8

Try this code,overflow will help to remove scrollbar.You can use it also for any div which is scrolling.

html, body {
   overflow-x: hidden;
 }
body {
   width:100%;
 }
Run Code Online (Sandbox Code Playgroud)


Jam*_*ruk 6

对我来说,视口元标记实际上在黑莓上引起了水平滚动问题.

content="initial-scale=1.0; maximum-scale=1.0;从视口标记中删除了它并修复了问题.以下是我当前的视口标记:

<meta name="viewport" content="user-scalable=0;"/>
Run Code Online (Sandbox Code Playgroud)

  • 如果您想让每个人都可以访问您的网站,这不是一个好主意。阅读:https://adrianroselli.com/2015/10/dont-disable-zoom.html (2认同)

Ron*_*ton 5

这适用于我在纵向和横向模式下的所有移动设备上。

<meta name="viewport" content="width=device-width, initial-scale = 0.86, maximum-scale=3.0, minimum-scale=0.86">