【问题标题】:Background images not resizing on mobile/iPhone背景图像无法在手机/iPhone 上调整大小
【发布时间】:2017-03-09 13:34:09
【问题描述】:

我有一个包含视差滚动的大图像的页面。

HTML:

<section class="parallax-top">
    <div class="caption">
    <h1><img src="../images/mainlogo.png" alt="Culture Smart!"></h1>
    <h2>Culture Smart! guides begin where other travel books end.</h2>
    <p>Our guides emphasize the people, not places. Written for the inquisitive traveler who wants more than information on hotels and sightseeing, they offer an insight into the rich human dimension of travel. Navigate your way abroad with over 100 country guides.</p>
    <p><a class="btn btn-primary btn-lg" href="destinations.php" role="button">Full list</a></p>
    </div>
</section>

<section class="box">
    <span class="border">
            <h2>About Culture Smart!</h2>
            <h4>The Essential Guide to Customs &amp; Culture</h4>
            <p>Culture Smart! provides essential information on attitudes, beliefs and behaviour in over 100 different countries.</p>
            <p><a class="btn btn-primary btn-lg" href="whatiscs.php" role="button">Learn more</a></p>
        </span>
</section>

<section class="parallax-middle">
    <div class="caption-middle">
        <span class="border-middle">
            <h2>News &amp; Promotions</h2>
            <h4>Find out what is going on around the world</h4>
            <p><a class="btn btn-primary btn-lg" href="news.php" role="button">Latest</a></p>
        </span>
    </div>
</section>

<section class="box">
    <span class="border">
            <h2>Our Authors</h2>
            <p>Find out their stories and experiences and how they can help enrich your travels.</p>
            <p><a class="btn btn-primary btn-lg" href="authors.php" role="button">About them</a></p>
        </span>
</section>

<section class="parallax-bottom">
    <div class="caption-bottom">
        <span class="border-bottom">
            <h2>We would love to hear from you</h2>
            <h4>Idea for the next book, let us know what you think of Culture Smart.</h4>
            <p><a class="btn btn-primary btn-lg" href="contact.php" role="button">Get in touch</a></p>
        </span>
    </div>
</section>

CSS:

.parallax-top {
  background-image: url("../images/hero3.jpg");  
  height: 1200px;
  background-attachment: fixed;
  background-position: top;
  background-repeat: no-repeat;
  background-size: cover;
  overflow: hidden;
}

.main .caption {  
    position: absolute;
    left: 0;
    top: 40%;
    width: 100%;
    text-align: center;
    color: white;
    background-color: black;
    opacity: 0.75;
    height: auto;
    padding: 0;
}

.main .caption h1 {
  margin-top: 0px;
}

.main .caption p {
  width: 80%;
  margin: auto;
  margin-bottom: 10px;
}


.parallax-middle {
  background-image: url("../images/hero1.jpg"); 
  height: 1200px;
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.caption-middle {  
    position: relative;
    left: 0;
    top: 40%;
    width: 100%;
    text-align: center;
    color: white;
    font-size: 20px;
    background-color: black;
    opacity: 0.75;
    height: auto;
    padding: 1%;
}

.parallax-bottom {
  background-image: url("../images/hero2.jpg"); 
  height: 1200px;
  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.caption-bottom {  
    position: relative;
    left: 0;
    top: 40%;
    width: 100%;
    text-align: center;
    color: white;
     background-color: black;
    opacity: 0.75;
    padding: 1%;
    height: auto;
}

当它显示在移动设备上时,图像会被放大,所以我看不到它们是什么。更改为“背景附件:滚动;”解决了这个问题,但我失去了电脑上的视差效果。有没有办法在手机上自动调整背景图像的大小?我不介意在移动设备上失去视差效果

【问题讨论】:

    标签: background-image parallax image-resizing


    【解决方案1】:

    您的 div 的高度可能是问题所在,您是否尝试过通过媒体查询或移动设备上的 background-size:contain 调整移动设备的高度?

    【讨论】:

    • 背景尺寸:在图像底部的空白处包含结果。如果您能建议一个合适的媒体查询以及如何使用,我将不胜感激
    • 我使用引导程序,所以这些是它的媒体查询 @media(max-width:767px){/*Screens below 767px*/} @media(min-width:768px)/*Screens from 766px up etc*/} @media(min-width:992px){} @media(min-width:1200px){} 您可以在每个查询中为每个屏幕尺寸编写全新的样式。
    • 和每一个加载不同的背景图片或改变高度?感谢您抽出宝贵时间
    • 是的,所以你可以有 @media(max-width:767px){.parallax-middle{height:300px;}} @media(min-width:768px){.parallax-middle{height :1200px;}} 或不同的背景图像,并将屏幕大小像素设置为您喜欢的任何值。
    • 老大!非常感谢
    猜你喜欢
    • 2017-01-16
    • 2018-07-28
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多