简体   繁体   English

当用户水平滚动时,div的背景色不会超出初始视图

[英]Background-color of div does not display beyond initial view when user scrolls horizontally

I have a banner at the top of my webpage, which needs to span the width of the user's screen. 我的网页顶部有一个横幅,该横幅需要跨越用户屏幕的宽度。 If the content beneath the banner is wider than the user's screen the banner needs to extend to be as wide as the content below so that it's visible when the user scrolls horizontally. 如果横幅下面的内容比用户的屏幕宽,则横幅需要扩展到与下面的内容一样宽,以便在用户水平滚动时可见。

My webpage appears to display fine on desktops that I've tried having ie, firefox, and safari. 我的网页在尝试安装了Firefox和Safari的台式机上显示正常。 It also displays fine on Android phones. 在Android手机上也可以正常显示。 However, it does not display properly on iPhone. 但是,它无法在iPhone上正确显示。

I've tried stripping the webpage down to something easy to follow in order to get to the crux of the issue. 我试图将网页简化为易于理解的地方,以解决问题的症结所在。 Interestingly, this bare-bones page exhibits the display issue in Android too. 有趣的是,这个基本页面也显示了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>

I think I understand the cause of this issue. 我认为我了解此问题的原因。 The div "graphic_top" is declared to have a width of 100%. div“ graphic_top”声明为100%的宽度。 Apparently this is 100% of the device's width. 显然,这是设备宽度的100%。

Is there a way to make the div expand horizontally to fit the content within? 有没有办法使div水平扩展以适合其中的内容?

如果您将#graphic_top更改为使用min-width:890px而不是100%,则它会一直沿用,但对于台式机而言仍会更宽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用iPhone上的引导程序,背景色无法适应div - Background-color doesn't stretch to fit the div using bootstrap on iPhone 边距:手机上的0自动总是将边距background-color设置为element background-color - Margin: 0 auto on mobiles always sets margin background-color to element background-color 在警报视图中,如何更改背景颜色并显示视图底部? - In the alert view ,how to change background color & display bottom of view? 在UIView中将背景颜色从一种颜色淡化为另一种颜色 - Fade background-color from one color to another in a UIView 如何显示带有哈希值的图像视图背景色 - how to display image view background color with hash value 在iPhone上水平滚动的UIPickerView? - UIPickerView that scrolls horizontally on the iPhone? 滚动视图滚动时,scrollview的子视图不会触摸事件 - scrollview's subview does not get touch events when scroll view scrolls TableView滚动到最后一个单元格之外 - TableView scrolls beyond the last cell 为什么我的应用程序在用户向下滚动UITableView时退出,超过最后一个单元格? - Why does my app quit when user scrolls down the UITableView, past the last cell? 启动时iphone表视图滚动到底部 - iphone table view scrolls to bottom when launch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM