<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS Background Examples</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.background-color {
height: 100vh;
background-color: #8BC34A; /* 使用颜色名称或十六进制值 */
color: white;
display: flex;
justify-content: center;
align-items: center;
}
.background-image {
height: 100vh;
background-image: url('https://via.placeholder.com/150'); /* 使用在线图片作为背景 */
background-size: cover;
background-position: center;
color: white;
display: flex;
justify-content: center;
align-items: center;
}
.background-gradient {
height: 100vh;
background: linear-gradient(45deg, #FFEB3B, #FF5722); /* 线性渐变 */
color: white;
display: flex;
justify-content: center;
align-items: center;
}
.background-multiple {
height: 100vh;
background:
linear-gradient(to right, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
url('https://via.placeholder.com/150'); /* 图片与渐变叠加 */
background-size: cover;
background-position: center;
color: white;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div class="background-color">
<h1>纯色背景</h1>
</div>
<div class="background-image">
<h1>图片背景</h1>
</div>
<div class="background-gradient">
<h1>渐变背景</h1>
</div>
<div class="background-multiple">
<h1>多层背景(图片+渐变)</h1>
</div>
</body>
</html>