【问题标题】:Background image size on mobile devices移动设备上的背景图像大小
【发布时间】:2016-02-15 05:59:57
【问题描述】:

我的背景图片似乎无法在移动设备上显示。它在缩放到移动大小的桌面浏览器上看起来不错,但在我的 iPhone 上的 Safari 上加载时它不会出现。链接是:http://lamda.jwoods.me/。我已经包含了相关的 HTML 和 CSS 以及它在我的手机上的显示方式以供参考。

HTML:

<div class="jumbotron main-jumbo">
  <nav class="navbar transparent navbar-default navbar-fixed-top" role="navigation">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#">The Drama Centre</a>
      </div>
      <div id="navbar" class="navbar-collapse collapse">
        <ul class="nav navbar-nav">
          <li><a href="index.html">Home</a></li>
          <li><a href="lamda.html">About LAMDA</a></li>
          <li><a href="benefits.html">Benefits</a></li>
          <li><a href="classes.html">Classes</a></li>
          <li><a href="teachers.html">Teachers</a></li>
          <li><a href="contact.html">Contact</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right hidden-sm hidden-xs">
          <li class="visible-lg-block"><a class="navtext">Follow us: </a></li>
          <li><a href="#fb"><i class="fa fa-facebook-official fa-2x"></i></a></li>
          <li><a href="#tw"><i class="fa fa-twitter fa-2x"></i></a></li>
          <li><a href="#ig"><i class="fa fa-instagram fa-2x"></i></a></li>
        </ul>
      </div>
    </div>
  </nav>

  <div class="container jumbo-container">
        <h1> The Drama Centre </h1>

        <h4> A leading LAMDA specific centre in Wiltshire </h4>

  </div>

</div>

CSS:

.main-jumbo {
  background:
    linear-gradient(
      rgba(0, 0, 0, 0.3),
      rgba(0, 0, 0, 0.0)
    ),
  url("../img/jumbobgweb.jpg");

    background-repeat: no-repeat;
    background-position: center;
    background-attachment: fixed;
    webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
  margin-bottom: 100px;
  min-height: 60

.main-jumbo h1, .main-jumbo h4{
  color: white;
  text-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}


.jumbo-container {
  display: flex;
  justify-content: center;
  flex-direction: column;
  height: 400px;
}

手机图片:

【问题讨论】:

  • 不重复,更新到那个代码还是一样的问题

标签: html css responsive-design


【解决方案1】:

添加这行 CSS 解决了我的问题:

@media (max-width: 768px) {
    .main-jumbo {
      background-attachment: scroll;
  }
}

显然背景附件:滚动在移动设备上的效果比在固定设备上好得多。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-27
    • 2017-11-27
    • 2014-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    • 2018-02-13
    相关资源
    最近更新 更多