CSS 背景(background)
目标
- 理解
- 背景的作用
- css背景图片和插入图片的区别
- 应用
- 通过css背景属性,给页面元素添加背景样式
- 能设置不同的背景图片位置
4.1 背景颜色(color)
- 语法:
background-color:颜色值; 默认的值是 transparent 透明的
4.2 背景图片(image)
- 语法:
```css
background-image : none | url (url)
```
| 参数 | 作用 |
| ---- | :----------------------------: |
| none | 无背景图(默认的) |
| url | 使用绝对或相对地址指定背景图像 |
`css
background-image : url(images/demo.png);
- 小技巧: 我们提倡 背景图片后面的地址,url不要加引号。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.bg {
width: 800px;
height: 500px;
background-color: pink;
/*背景图片 1. 必须加url 2. url 里面的地址不要加 引号*/
background-image: url(images/l.jpg);
}
</style>
</head>
<body>
<div class="bg">
12312312312312312312312312312
</div>
</body>
</html>
4.3 背景平铺(repeat)
- 语法:
```css
background-repeat : repeat | no-repeat | repeat-x | repeat-y
```
| 参数 | 作用 |
| --------- | :----------------------------------: |
| repeat | 背景图像在纵向和横向上平铺(默认的) |
| no-repeat | 背景图像不平铺 |
| repeat-x | 背景图像在横向上平铺 |
| repeat-y | 背景图像在纵向平铺 |
<