CSS 背景图像不在移动设备上滚动

标签 css html twitter-bootstrap background



向下滚动页面时,我有一个背景图像保持在原位。 在这里查看 JSFiddle:JS Fiddle
代码

body {
  font-family: 'Open Sans', sans-serif;
  background-image: url("http://vrexpert.virtualrealities.netdna-cdn.com/wp-content/uploads/2015/12/Google5.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  width: 100%;
  height: 100%;
  background-attachment: fixed;
  overflow-x: hidden !important;
  }


但是
这在使用移动设备时不会应用。(例如,我使用的是 iPad)。图片不随页面滚动。

如何在移动设备上获得与在桌面设备上相同的结果?

最佳答案

尝试以下操作:(改编自 background: fixed no repeat not working on mobile)

body:before {
  font-family: 'Open Sans', sans-serif;
  content: "";
  display: block;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: -10;
  background: url("http://vrexpert.virtualrealities.netdna-cdn.com/wp-content/uploads/2015/12/Google5.jpg") no-repeat center center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

关于CSS 背景图像不在移动设备上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34271090/

相关文章:

css - <li> 在 IE 上看起来很奇怪

CSS LESS 占位符混合

css - 如何并排获取div

html - 无法设置 html div 宽度

javascript - 如果输入为空,我该怎么做,什么都不会发生

html - 分别调整div中2个span元素的高度

jquery - HTML Bootstrap 3 不向 UL LI 添加事件类

jquery - CSS Sprite 、jQuery 淡入/淡出、透明 PNG 和 IE : wtf?

javascript - 删除类和点击另一个写类的js或css怎么写

jquery-ui - 如何在 Bootstrap 模式上修改 jquery-ui 对话框