学习-WEB前端快速入门-23.25_26_CSS样式表_背景样式设计

236 阅读1分钟
一、background-color 背景颜色
默认值:transparent(透明色)
<div class="div1"></div>
.div1{background-color:red}

二、background-image 背景图片
默认值:none(没有图片)
<div class="div1"></div>
.div1{ background-image: url("img/testImg.png";); }

三、background-repeat 背景重复
  默认值:repeat(整体平铺)
  属性值:
        repeat-x只有水平方向采用平铺
        repeat-y只有垂直方向采用平铺
        no-repeat不采用平铺
       

四、background-position 背景位置
  默认值:0% 0%
  属性值:(在容器中,摆放位置)
        方位 方位
        像素 像素
        百分比 百分比

五、background-attachment 背景附着
 属性值:scroll 附着于元素,随着窗口移动而移动
        fixed  附着于窗口,随着窗口的移动而不移动,参照物相对于窗口
 
 

六、background背景复合属性
  作用:一次性设置元素的所有背景相关属性
  格式:background:背景颜色、背景图片、背景重复、背景附着、背景位置
  
 

七、background-size背景大小
  默认值:auto背景图片本身真实大小
  属性值:像素 像素
         百分比 百分比
       

🌟备注:如果复合属性于background-size要求同时存在,必须分开写。不可将background-size写到background:里面