一、背景属性

1.背景颜色属性 background-color(简写background)
2.背景图片 background-image
属性值: url(图片的路径地址),不占位置(需要父级容器支持),默认平铺,沾满容器
3.背景图片的平铺设置 background-repeat
属性值: 默认repeat,常用的属性值 no-repeat 不平铺 只会显示一张背景图
4.背景定位属性 background-position
属性值:x轴方向 left right center;y轴方向 top bottom center;在水平垂直方向设置坐标值,数值+单位(数值可正可负)
5.背景固定属性:background-attachment
属性值:scroll 滚动,fixed 固定
6.简写方式 background
属性值: 将前面的属性作为属性值使用 background-color background-image background-repeat background-position background-attachment

二、示例

background: pink url(https://xxxxxx) no-repeat center;
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      div {
        width: 500px;
        height: 500px;
        border: 1px solid #000;
        background: pink url(https://xxxxxx) no-repeat center;
      }
    </style>
  </head>
  <body>
    <div></div>
  </body>
</html>
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐