1、background
背景颜色,background-color:pink;
背景图片,background-image:url(images/longyi2.jpg);
NOTES:背景图片不要加引号。
background-imgae和<img src="">区别就是:
1、img只插入一张照片,而background-image则是在块中作为背景,可重复N次。
2、img设置大小则图片大小改变,而块中只能改变块的范围大小。
background-repeat:默认repeat(平铺),repeat-x(横向平铺),repeat-y(纵向平铺),no-repeat(不平埔)
背景位置,background-position(重点掌握)
可以跟
length | 百分数 | 由浮点数和单位标识符组成的长度值 |
position | top、center、bottom、left、right等方位名词 |
例如:将图片放置在div中的水平居中
<!DOCTYPE html>
<html lang="zh">
<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></title>
<style>
.nav
{
width: 800px;
height: 500px;
background-image: url(images/longyi2.jpg);
background-repeat: no-repeat;
background-position: center center;
border: 1px solid black;
}
</style>
</head>
<body>
<div class="nav">
</div>
</body>
</html>
NOTES:
1、background-position必须给定background-image:url();
2、background-position后面两个值,x & y 例如:background-position:10px 50px;或background-position:left center;
以及background-position:20px center;(X轴为20px,而y为垂直居中。)
背景附着 background-attachment
属性中主要有两个值,一个是scoll(滚动的)、另一个是fixed(固定的)
背景简写:背景颜色、背景图片地址、背景平铺、背景滚动、背景位置。
例如:
body
{
background:pink url(images/picture.jpg) no-repeat fixed 20px center;
}
CSS3中背景透明background:rgba(red,green,blue,transparent)
例如:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.transparent
{
width: 120px;
height: 50px;
background:rgba(0,0,0,0.6);
}
</style>
</head>
<body>
<div class="transparent">
</div>
</body>
</html>