android - 修复了安卓和苹果设备的背景

标签 android html ios css background-size

所以这是我的问题。我使用以下代码将背景图片设置为页面:

.page-content{
    background-image: url("../../../../assets/pages/media/bg/3.jpg");
    background-repeat: no-repeat;
    background-position: right top;
    background-attachment: fixed;
    background-size:cover;

}

似乎工作正常。然后我为移动版本添加了一些

@media(max-width:991px){.page-content{
    background-attachment: scroll;
    }
}

我尝试将 background-size 设置为封面、首字母,甚至尝试使用百分比。问题是在移动设备上,背景不会停留在屏幕上。当我向下滚动时,它会与其余内容一起上升。

任何帮助将不胜感激。

最佳答案

我相信大多数(如果不是所有的话)手机都不支持固定背景图片。你所要做的就是将图像放在一个固定位置的单独的 div 中。以下代码由@vincent提供 - background: fixed no repeat not working on mobile 它用于 body 元素,但我相信您可以对其进行调整以满足您的需要。

body:before {
  content: "";
  display: block;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  z-index: -10;
  background: url(photos/2452.jpg) no-repeat center center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

关于android - 修复了安卓和苹果设备的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46598924/

相关文章:

android - 强制终止时重新启动应用程序

html - 添加border-top时如何让元素保持不向下移动

javascript - 如何单步执行绑定(bind)到按钮的 JavaScript 代码

php - 允许用户找到半径内的其他用户

ios - 获取拥有 iDevice 的联系人

ios - 将 MapKit 区域上传到 firebase

android - 切换方向错误 : Fragment Error - Duplicate id, 标记,或父 id 0x0

android - Malformed Manifest - 找不到元素 list 的声明

java - 安卓工作室 : ListView On Touch Event

ios - iOS 中的 MVVM 示例/示例实现