css中background的合并写法

博主:jhchinajhchina 2023-07-31 173 0条评论
摘要: ------------------适用于项目中设定背景图片的代码-------------------background: red url(./images...

------------------适用于项目中设定背景图片的代码-------------------

background: red url(./images/wx1.jpg) center center / cover no-repeat;

或者

background: red url(./images/wx1/jpg) no-repeat center center / cover;

两种写法的效果是一样的。

例子:

background: #ff0000 url(/i/eg_bg_03.gif) no-repeat fixed center / cover;

这些参数从左到右依次是:

background-color

background-image

background-repeat

background-attachment

background-position / background-size

值得注意的是background-size是CSS3的属性,它要与background-position配合使用,中间有一个斜杠分隔符。