gpt4 book ai didi

CSS - 带有一些透明像素的图像周围的背景颜色

转载 作者:太空宇宙 更新时间:2023-11-03 22:26:46 28 4
gpt4 key购买 nike

我有一个固定大小的图像,其中一部分是透明的,我目前将其用作 DIV 背景。我必须将图像精确地放在屏幕中心

问题是我需要图像周围的所有空间都是黑色的。如果我将其设置为 background: black url(... - 图像的透明像素也会变成黑色,这是错误的。

另一个问题是网站内容是动态的,所以我不能用 2 个具有相同背景图像和不同过滤器的 DIV 作弊。我需要清楚地透过透明像素。

我当前的代码:

<html>
<head>
<style>
.image {
height: 100%;
background: black url(image.png) center center no-repeat;
background-size: auto 100%;
}
</style>
</head>

<body>
<div class="image"></div>
</body>
</html>

简而言之——我需要通过图像的透明部分来查看内容,屏幕的另一部分必须是黑色的。我如何实现这一点?

最佳答案

我建议使用巨大框阴影;

body {
background: pink;
display: flex;
height: 100vh;
}

.wrap {
height: 200px;
width: 200px;
border: 1px solid green;
margin: auto;
background-image: url(https://www199.lunapic.com/editor/premade/transparent.gif);
background-size: 200px;
background-repeat: no-repeat;
background-position: center;
padding: 20px;
box-shadow: 0 0 0 2000px red;
}
<div class="wrap"></div>

关于CSS - 带有一些透明像素的图像周围的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50682993/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com