目录
使用方法:
background-repeat: repeat | no-repeat | repeat-x | repeat-y
参数值 | 作用 |
---|---|
repeat | 背景图片在纵向和横向上平铺(默认) |
no-repeat | 背景图片不平铺 |
repeat-x | 背景图片在横向上平铺 |
repeat-y | 背景图片在纵向上平铺 |
repeat
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
/* 默认repeat平铺 */
width: 500px;
height: 500px;
background-color: #ccc;
background-image: url(./images/logo.png);
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
no-repeat
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 500px;
height: 500px;
background-color: #ccc;
background-image: url(./images/logo.png);
/* no-repeat 不平铺 用的最多*/
background-repeat: no-repeat;
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
repeat-x
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 500px;
height: 500px;
background-color: #ccc;
background-image: url(./images/logo.png);
/* 水平方向上平铺 */
background-repeat: repeat-x;
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
repeat-y
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 500px;
height: 500px;
background-color: #ccc;
background-image: url(./images/logo.png);
/* 垂直方向上平铺 */
background-repeat: repeat-y;
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>