首页 > 其他 > 详细

关于固定背景图片的方法

时间:2018-06-08 11:17:47      阅读:158      评论:0      收藏:0      [点我收藏+]

使用background-attachment: fixed;使背景图片固定

body 
  { 
  background-image: url(bgimage.gif); 
  background-attachment: fixed;
  }

这是css的属性,所有浏览器都支持 background-attachment 属性。

 

但是在ios和一些移动端对background-attachment: fixed支持的不好,但可以hack一下。:

body:before {
  content: ‘ ‘;
  position: fixed;
  z-index: 0;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: url(path/to/image) center 0 no-repeat;
  background-size: cover;
}

 

总结:移动端要固定背景图片的话就用第二种方法,pc用第一种。

   不要两种一起写,会有影响。

 

关于固定背景图片的方法

原文:https://www.cnblogs.com/guan905883/p/9154463.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!