防止移动设备中的水平滚动

时间:2013-05-21 06:35:37

标签: css mobile

我在顶部有一条很长的路线:

#top-line {
  background: #00A1E0;
  border-bottom: 1px solid #FFF;
  height: 4px;
  position: absolute;
  top: 0;
  left: 0;
  width: 10000px;
}

所以我使用overflow-x: hidden来阻止水平滚动:

html {
  overflow-x: hidden;
  height: 100%;
}
body {
  background: #EDEDED;
    font-size: 12px;
    font-family: Arial, sans-serif;
    color: #666;
  height: 100%;
  overflow-x: hidden;
}

它运作正常,但在手机中我仍然可以无限期地向右滚动。

有没有解决方法呢?

4 个答案:

答案 0 :(得分:3)

您应该定义宽度:100%或最大宽度:100%以防止水平滚动,因为您定义了移动设备可以占用的区域的宽度,并且其性质占用的宽度超过移动宽度本身的宽度所以定义为100%将其限制为移动宽度。

答案 1 :(得分:2)

定义体宽

body{
 width:320px//or 100%;
 overflow-x:hidden;
}

答案 2 :(得分:0)

如果你最终在这里,你可能想要尝试的另一件事是在html头中调整这个元标记:

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

答案 3 :(得分:-2)

html body(tag)
ontouchmove="blockMove()"

js(document)
function blockMove() {event.preventDefault() ;}