1、html中将需要加背景图的div(other-product)包裹住定位文字的div(other-product-box)和遮罩层的div(indexInner)

2、设置最外边框CSS样式
.other-product{
position: relative;
background-size: 100%;
background-size: 100% 100%;
background-repeat: no-repeat;
min-height: 675px;
background-size: 100%;
}
3、设置遮罩层的CSS样式
.indexInner{
background: rgba(0,0,0,0.4);
height: 675px;
width: 100%;
position: absolute;
left: 0;
top: 0;
z-index: 2;
}
4、设置最上层文字div的CSS样式
.other-product-box{
position: absolute;
margin: 0 auto;
width: 100%;
-webkit-box-sizing: border-box;
padding: 0 10px;
z-index: 999;
max-width: 1180px;
left: 152px;
}
5、完结
这篇博客详细介绍了如何在HTML中使用CSS为div元素添加背景图,并将文字div和遮罩层有效结合。通过设置`.other-product`的背景样式,确保背景图片全尺寸填充且不重复。同时,创建了一个`.indexInner`遮罩层,使用 rgba 颜色实现半透明效果,并通过绝对定位覆盖在背景之上。最后,设置了`.other-product-box`的文字div,确保其在遮罩层上方并居中显示,从而达到理想的页面布局效果。
340

被折叠的 条评论
为什么被折叠?



