css - 背景图片在手机上放大太多

标签 css google-chrome responsive-design

我的 RWD 页面有奇怪的问题。我有一个具有以下样式的背景图片:

#background-image {
  width: 100%;
  height: 100%;
  opacity: 0.5;
  position: absolute;
  z-index: -1;
  background-image: url('../landing.jpeg');
  background-attachment: fixed;
  background-size: cover;
  background-position: 85% 50%;
  background-repeat: no-repeat;
}

当我在 Chrome DevTools(和 FF)中处于移动模式时,一切看起来都正常:

enter image description here

但是在真正的移动浏览器上这个背景变得太大了:

enter image description here

可能是什么原因?我的移动浏览器是 Android 上的 Chrome 63,我的桌面浏览器是 Ubuntu 上的 Chrome 59。

最佳答案

这是因为 background-attachment: fixed 设置在移动浏览器上不起作用...

尝试删除 background-attachment 属性并将 position 属性更改为 fixed,如下所示:

#background-image {
  width: 100%;
  height: 100%;
  opacity: 0.5;
  position: fixed;
  z-index: -1;
  background-image: url('../landing.jpeg');
  background-size: cover;
  background-position: 85% 50%;
  background-repeat: no-repeat;
}

希望这会有所帮助...

关于css - 背景图片在手机上放大太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47904811/

相关文章:

java - 在struts2 jsp页面中包含css

html - 如何使 anchor 元素 (<a>) 的大小与列表项 (<li>) 的大小相同

html - 谷歌浏览器中的滚动条问题

javascript - Chrome 扩展程序填写所选字段

html - 如何使用bootstrap4隐藏移动设备的元素?

css - 具有多个级别的响应式 CSS 菜单

html - Spectre.css - 将 flexbox 拆分到另一行而不是缩小?

html - 移动设备响应式网站

css - “text-decoration” 和 “:after” 伪元素,在 Firefox 8 中

html - CSS :invalid works differently in Chrome v. FF?