Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 当用户水平滚动时,div的背景色不会显示在初始视图之外_Iphone_Android_Html_Width - Fatal编程技术网

Iphone 当用户水平滚动时,div的背景色不会显示在初始视图之外

Iphone 当用户水平滚动时,div的背景色不会显示在初始视图之外,iphone,android,html,width,Iphone,Android,Html,Width,我有一个横幅在我的网页顶部,它需要跨越用户的屏幕宽度。如果横幅下的内容比用户屏幕宽,则横幅需要延伸到与下面的内容一样宽,以便在用户水平滚动时可见 我的网页在我尝试过ie、firefox和safari的桌面上显示得很好。它在Android手机上也显示良好。但是,它不能在iPhone上正确显示 我试着将网页剥离成易于理解的内容,以便找到问题的症结所在。有趣的是,这个简陋的页面也展示了Android的显示问题 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.

我有一个横幅在我的网页顶部,它需要跨越用户的屏幕宽度。如果横幅下的内容比用户屏幕宽,则横幅需要延伸到与下面的内容一样宽,以便在用户水平滚动时可见

我的网页在我尝试过ie、firefox和safari的桌面上显示得很好。它在Android手机上也显示良好。但是,它不能在iPhone上正确显示

我试着将网页剥离成易于理解的内容,以便找到问题的症结所在。有趣的是,这个简陋的页面也展示了Android的显示问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width"/>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />

<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0px; padding: 0px }
  #graphic_top {width: 100%; height: 48px; background-color: #637768;}
</style>

</head>

<body>
<div id="graphic_top"> <!-- displays a green banner across the top -->
<div style="width: 890px; margin: 0 auto;">  
<p>Scroll horizontally on an iPhone or Android phone and you will see that the green background-color
   in "graphic_top" does not extend beyond the width of the device's screen.
</p>
</div>


</div>
</body>
</html>

html{高度:100%}
正文{高度:100%;边距:0px;填充:0px}
#图形顶部{宽度:100%;高度:48px;背景色:#637768;}
在iPhone或Android手机上水平滚动,您将看到绿色背景色
在“graphic_top”(图形顶部)中,不超出设备屏幕的宽度。

我想我理解这个问题的原因。div“graphic_top”的宽度声明为100%。显然,这是设备宽度的100%

有没有办法使div水平扩展以适应其中的内容?

如果您将#graphic_top更改为使用最小宽度:890px而不是100%,那么它将一直横向扩展,但对于台式机来说仍然会更宽