如果要在HTML页面上对背景进行平铺,可以通过background-repeat设置。默认情况下背景图片是平铺的。
- 示例:背景图片不平铺
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 300px;
height: 300px;
background-image: url('images/logo.png');
background-repeat: no-repeat;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
展示效果:
- 示例:背景图片沿X轴平铺
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 300px;
height: 300px;
background-image: url('images/logo.png');
background-repeat: repeat-x;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
展示效果:
- 示例:背景图片沿y轴平铺
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 300px;
height: 300px;
background-image: url('images/logo.png');
background-repeat: repeat-y;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
展示效果:
- 示例:背景图片平铺
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 300px;
height: 300px;
background-image: url('images/logo.png');
background-repeat: repeat;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
展示效果: