辣鱼

02CSS:背景属性

技术  ·  

CSS的背景属性可以定义元素背景颜色、背景图片等。

02.1背景颜色属性

CSS使用background-color定义背景颜色。
实例语法:

body {
background-color: red;
}

背景属性值可以是颜色词、十六进制的颜色、RGB、RGBA。

02.2背景图片属性

CSS使用background-image定义背景图片。

body {
background-image: url("./image1.png);
background-repeat: no-repeat;
background-size: cover;
background-position: center top;
}

背景图片属性值为url().
背景图片background-repeat属性值表示是否平铺(铺满容器)。
背景大小属性background-size属性值可以是像素、百分比、cover……
背景图片的位置属性background-position值(默认值是背景图的0 0)可以是像素、百分比、(left top right bottom)位置组合。

background-repeat的值

描述
no-repeat默认值,不重复铺满
repeat重复铺满
background-size的值
描述
120px 120px款120像素 高120像素
100% 50%宽度100% 高度50%
cover根据图像覆盖
background-position的值
描述
20px 20px取图片的20px 20px坐标为起始点取background-size大小
50% 50%取图片50% 50%坐标位置为起始点,取background-size大小,默认为0% 0%位置
left top左 上
left center左 中
left bottom左下
right top右 上
right center右 中
right bottom右 下
center center中 中
center top中 上
center bottom中 下

#

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注