我现在想设置一张图片作为背景图填满整个div,当我使用合并写法
也就是如下:
background: url(../../assets/images/ml.png) 0 0 / 100% 100% no-repeat fixed;
图片不会填满整个div,只会在div中显示一个角(图片比div大),但是我设置了0 0/100% 100%
,当我去掉fixed
的时候,如下
background: url(../../assets/images/ml.png) 0 0 / 100% 100% no-repeat;
图片很好的显示作为背景图展示出来了,大小正好填充div。
这是为什么呢?我是按照background:bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;
这个顺序编写的css?
如果你只想将背景填充
div
,直接使用background-size: 100% 100%
即可。background-attachment: fixed
是指背景图片固定在视口,不随着元素内容而滚动。不要混淆这两个概念。