在手机上覆盖背景大小

Cover background-size on mobile

我的网站有问题。图片在桌面上看起来不错,但在我的 phone 上看起来很糟糕,因为它放大了。

我该如何解决这个问题? 它不适用于

background-size:cover;

跟背景的div有两个类

.content{
    color: white; 
    font-family: "Another Typewriter"; 
    width:100%; height:1000px;  
    font-size: 300%; 
    padding-left: 15%; 
    padding-right: 15%; 
    padding-top: 10%; 
    text-align: center; 
    background-size: cover;
}

.parallax{
    height: 100%; 
    background-attachment: fixed; 
    background-position: center; 
    background-repeat: no-repeat; 
    background-size: cover;
}
#xyz{background-image: url(URLtoimage);}

Div 容器:

    <div id="xyz" class="parallax content">
    <legend class="text-center content-headline">XYZ</legend>
Some text
    </div>

也许你可以把它改成background-size: contain when the screen width is smaller than 767px

我怎么假设你正在使用 background-attachment: fixed; ,它不能在许多移动浏览器上工作你必须使用媒体查询在小屏幕滚动时更改它。

.parallax{
   height: 100%; 
   background-attachment: fixed; 
   background-position: center; 
   background-repeat: no-repeat; 
   background-size: cover;
}

@media screen and (max-width: 600px) {
   .parallax {
        background-attachment: scroll; 
    }
}

使用背景尺寸:100% 100%;检查片段视图。

body{
margin:0;
}
.bg-img {
  background: url('http://www.planwallpaper.com/static/images/6942095-abstract-background-wallpaper.jpg') no-repeat center;
  background-size: 100% 100%;
  min-height: 100vh;
  width: 100%;
}
<div class="bg-img">

</div>