我在github页面上有website,它可以在任何桌面浏览器上正常工作。但是,我的两个背景图像不会显示在移动设备上(我只测试过iPad和iPhone,它可能只是IOS)。我试图添加媒体查询,以确保手持设备上的background-attachment
属性设置为scroll
(我读过这有时是问题)。我也有媒体查询,以确保图像不会太大,无法加载。这里是我的html:背景图像不显示/延伸在iPad或iPhone上
<div id="image-1" class="background-image"></div>
<div id="image-2" class="background-image"></div>
这里的CSS:
#image-1 {
background-image: url('imgs/coding.jpg');
}
#image-2 {
background-image: url("imgs/game.JPG");
}
@media only screen and (min-width: 500px) {
/* For mobile phones: */
#image-1 {
background-image: url("imgs/coding-large.jpg");
}
#image-2 {
background-image: url("imgs/game-large.jpg");
}
}
@media not handheld {
.background-image {
background-attachment: fixed;
}
}
.background-image {
opacity: 0.8;
background-repeat: no-repeat;
background-attachment: scroll;
background-size: 100% 100vh;
height: 85vh;
}
如果我改变100vh至100%,然后将图像加载,但他们可怕的垂直拉伸。有什么建议么?