如何在iOS Safari中(在实际设备上)“裁剪”屏幕外的<div>?</div>

时间:2013-01-10 09:30:05

标签: ios ipad safari scroll css

我在一个全宽度的页面上有一些屏幕外的div(稍后会在变换中移动),但iOS safari(在实际设备上)只是不裁剪它,而是扩展了可滚动区域。

你可以看到这个设置(300x300盒子向右移动-100)在行动中(在iPad上浏览,桌面工作正常):http://www.eppz.eu/responsive/offscreen.html

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
<title>Off screen divs</title>
<style type="text/css">

    body
    {
        margin: 0px;
        width: 100%;
        overflow:hidden; /* Can't crop with this :( */

        background: url('tile.png');
    }

    #offScreen
    {
        width: 300px;
        height: 300px;
        margin-left: auto; /* To the right */

        position: relative;
        right: -100px; /* Nudge offscreen */

        background: url('300.png');
    }

</style>
</head>

<body>

    <div id="offScreen"></div>

</body>
</html>

我在iPad上检查过它,计算出的身体样式似乎很好(宽度为768px):

background-attachment: scroll;
background-clip: border-box;
background-color: 
rgba(0, 0, 0, 0);
background-image: url(http://eppz.eu/responsive/tile.png);
background-origin: padding-box;
display: block;
height: 300px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
overflow-x: hidden;
overflow-y: hidden;
width: 768px;

如何在这里防止水平滚动的野生动物园?我更喜欢只有CSS的解决方案,我没有太多意图“垃圾”标记。

1 个答案:

答案 0 :(得分:3)

Somewhy safari需要在 body 之后引入另一个包装器,然后一切都按预期工作。 类似的东西:

#view
{
    position:relative;
    top: 0px;
    left: 0px;
    right:0px;
    bottom:0px;
}