gpt4 book ai didi

css - 如何使用 CSS 将背景图像淡化为黑色?

转载 作者:技术小花猫 更新时间:2023-10-29 12:02:43 29 4
gpt4 key购买 nike

我想要一个不重复的背景图片。当图像结束时,它应该会逐渐淡化为黑色。

这是我的意思的一个例子,它只是错过了“软衰落”。图像突然结束并且有黑色,我想让这个过渡更平滑。这可能吗?

(图片随机来自google)

body {
background:url(http://www.stadtteilschule-oejendorf.de/Unterricht/files/stacks_image_2936.png) #000 no-repeat;
}

现场演示:http://jsfiddle.net/sMc8a/

最佳答案

您可以尝试使用此代码。 http://jsfiddle.net/sMc8a/3/

HTML

<div class="example">
Hello
</div>

CSS

body {
background: black;
}
.example {
width: 300px;
height: 300px;
background-image: -webkit-linear-gradient(top,
rgba(0,0,0,0.9) 0%,
rgba(0,0,0,0) 20%,
rgba(0,0,0,0) 80%,
rgba(0,0,0,0.9) 100%
),
-webkit-linear-gradient(left,
rgba(0,0,0,0.9) 0%,
rgba(0,0,0,0) 20%,
rgba(0,0,0,0) 80%,
rgba(0,0,0,0.9) 100%
),
url(http://www.stadtteilschule-oejendorf.de/Unterricht/files/stacks_image_2936.png);

background-image: -moz-linear-gradient(top,
rgba(0,0,0,0.9) 0%,
rgba(0,0,0,0) 20%,
rgba(0,0,0,0) 80%,
rgba(0,0,0,0.9) 100%
),
-moz-linear-gradient(left,
rgba(0,0,0,0.9) 0%,
rgba(0,0,0,0) 20%,
rgba(0,0,0,0) 80%,
rgba(0,0,0,0.9) 100%
),
url(http://www.stadtteilschule-oejendorf.de/Unterricht/files/stacks_image_2936.png);

background-image: -o-linear-gradient(top,
rgba(0,0,0,0.9) 0%,
rgba(0,0,0,0) 20%,
rgba(0,0,0,0) 80%,
rgba(0,0,0,0.9) 100%
),
-o-linear-gradient(left,
rgba(0,0,0,0.9) 0%,
rgba(0,0,0,0) 20%,
rgba(0,0,0,0) 80%,
rgba(0,0,0,0.9) 100%
),
url(http://www.stadtteilschule-oejendorf.de/Unterricht/files/stacks_image_2936.png);

background-image: linear-gradient(top,
rgba(0,0,0,0.9) 0%,
rgba(0,0,0,0) 20%,
rgba(0,0,0,0) 80%,
rgba(0,0,0,0.9) 100%
),
linear-gradient(left,
rgba(0,0,0,0.9) 0%,
rgba(0,0,0,0) 20%,
rgba(0,0,0,0) 80%,
rgba(0,0,0,0.9) 100%
),
url(http://www.stadtteilschule-oejendorf.de/Unterricht/files/stacks_image_2936.png);
}

关于css - 如何使用 CSS 将背景图像淡化为黑色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18562761/

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