柴油涨价,离骚易烊千玺,诛仙星泪
使用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用第一种。
不要两种一起写,会有影响。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
css3 flex布局 justify-content:space-between 最后一行左对齐
网友评论