gpt4 book ai didi

javascript - 基于背景图像的文本反转

转载 作者:太空狗 更新时间:2023-10-29 13:48:27 25 4
gpt4 key购买 nike

是否有可能仅使用 CSS/CSS3 或 javascript 获得类似的东西?但没有文字图片。

enter image description here

最佳答案

在旧浏览器的有限支持下,您可以通过文本剪辑来实现:

对于这个 html:

<div class="filter">
<div class="base">SOME TEXT</div>
</div>

使用那个 CSS:

.filter {
width: 250px;
height: 250px;
background: -webkit-linear-gradient(-45deg, black 0%,black 50%,white 51%,white 100%);
}
.base {
width: 100%;
height: 100%;
font-size: 80px;
background: -webkit-linear-gradient(-45deg, white 0%,white 50%,black 51%,black 100%);
-webkit-background-clip: text;
color: transparent;
}

您将从底部(具有第一个 div 的反转颜色)获得背景,仅通过文本显示。

webkit demo

编辑

发现可以在单个元素中完成。样式将是:

.base {
width: 100%;
height: 100%;
font-size: 80px;
background: -webkit-linear-gradient(-45deg, white 0%,white 50%,black 51%,black 100%), -webkit-linear-gradient(-45deg, black 0%,black 50%,white 51%,white 100%);
-webkit-background-clip: text, border;
color: transparent;
}

关于javascript - 基于背景图像的文本反转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16146167/

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