简体   繁体   English

覆盖手机的背景尺寸

[英]Cover background-size on mobile

I have a problem with my website. 我的网站有问题。 The picture looks great on the desktop but on my phone it looks terrible because its zoomed in. 该图片在桌面上看起来不错,但在我的手机上却因为放大而显得很糟糕。

How can I solve this? 我该如何解决? It don´t work with 它不能与

background-size:cover;

The div with the background have two classes 具有背景的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 Container: Div容器:

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

How I've assumed you're using background-attachment: fixed; 我认为您使用的是background-attachment: fixed; , it can't work on many mobile browser you must use media query to change it on scroll for little screen. ,它不能在许多移动浏览器上运行,您必须使用媒体查询才能在小屏幕上滚动更改它。

.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; 
    }
}

也许您可以将其更改为背景大小:当屏幕宽度小于767px时包含

use background-size:100% 100%; 使用背景大小:100%100%; Check the snippet view. 检查代码段视图。

 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> 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM