.element {
background-image: url('path-to-image.jpg');
background-size: cover; /* 确保图片覆盖整个元素 */
background-position: center; /* 将图片居中显示 */
min-height: 100vh; /* 确保至少为视口高度 */
}
.element {
background-image: url('path-to-image.jpg');
background-size: 100% 100%;
background-position: center;
background-attachment: fixed; /* 背景图片固定 */
min-height: 100vh; /* 至少为视口高度 */
}
.element {
position: relative;
min-height: 100vh;
}
.element::after {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: url('path-to-image.jpg');
background-size: cover;
background-position: center;
z-index: -1; /* 确保伪元素在内容下方 */
}