效果
原理
技巧来源:Amazon的产品列表页
通过底色与遮罩层的透明度搭配实现,整体的"去白底"效果
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>demo</title>
<style type="text/css">
.container {
display: flex;
gap: 10px;
padding: 2%;
background-color: #F7F7F7;
}
.product_picture {
width: 300px;
height: 300px;
}
.product_picture img {
width: 100%;
height: 100%;
}
.remove_white {
position: relative;
}
/* 这部分是重点 */
.remove_white::after {
position: absolute;
content: "";
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000; /* 重点 */
opacity: 0.03; /* 重点 */
pointer-events: none;
}
</style>
</head>
<body>
<div class="container">
<div class="product_picture">
<img src="https://img95.699pic.com/xsj/0r/c0/ri.jpg%21/fh/300" alt="" />
</div>
<div class="product_picture remove_white">
<img src="https://img95.699pic.com/xsj/0r/c0/ri.jpg%21/fh/300" alt="" />
</div>
</div>
<div class="container">
<div class="product_picture">
<img src="https://img0.baidu.com/it/u=2465119442,2617596469&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500" alt="" />
</div>
<div class="product_picture remove_white">
<img src="https://img0.baidu.com/it/u=2465119442,2617596469&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500" alt="" />
</div>
</div>
</body>
</html>