iPhone Div背景图像居中


iPhone Div Background Image Centering?

我的网站页脚有问题。

正如你在iPhone(Safari)上看到的那样,页脚图像显示不正确,并且跨越了网站的宽度。

这是页脚的代码:

.footer {
  width: 100%;
  height: 118px;
  background: #000000 url(../images/footer.png) top center !important;
  margin: 70px auto 0 auto;
}
<div class="footer">
  <div style="width:1100px;height:118px;margin:auto;">
    <div id="mc_embed_signup">
      <form action="http://SaveWithPride.us7.list-manage.com/subscribe/post?u=0beccc5a2d913b0527a748edc&amp;id=cb6e398bc5" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
        <input type="email" value="" name="EMAIL" class="email footer-field" id="mce-EMAIL" placeholder="enter your text" onfocus="this.placeholder = ''" onblur="this.placeholder = 'enter your text'" required>
        <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button footer-submit"></div>
      </form>
    </div>
    <div style="width:334px;height:118px;float:right;background:transparent;">
      <div class="socialtext">save with pride, socially:</div>
      <div class="twitter"></div>
      <div class="facebook"></div>
      <div class="footertext">© 2013 SaveWithPride.com&nbsp&nbspAll Rights Reserved.&nbsp&nbsp<a href="adamdworak.com">Design by A/D</a></div>
    </div>
  </div>
</div>

我在这里做错了什么?页脚背景(现在显示的)没有延伸到iPhone浏览器的边缘,似乎没有居中。我正在努力使它居中,并在我的电脑上显示100%的宽度。

那么页脚元素背景没有屏幕那么宽?尝试添加以下内容:

.footer {
    background-size: 100% 100%; /* stretches background */
}

尝试从.footer css 中删除宽度

此外,如果您希望将页面放入iPhone屏幕,请将.footer子div的宽度更改为940px,如下所示

<div class="footer">
   <div style="width:940px;height:118px;margin:auto;">

我说更改宽度是因为.footer设置为100%宽度,这将相当于iphone屏幕宽度,因此图像将仅延伸到屏幕宽度。问题是子div的宽度可能大于iPhone屏幕的宽度,这将需要用户进一步向右滚动,这也是图像没有拉伸的原因。