CSS-继承祖父母Div的颜色的透明文本

发布于 2025-02-10 08:55:16 字数 1020 浏览 2 评论 0原文

我正在制作个人网站。我想添加一些有趣的东西,让人们写信给我的“墙”。这个想法是要有一个是线性梯度的祖父母div,是黑色的父级,与祖父母div匹配的文字(梯度的一部分将在文本下。我知道我可以给文本相同 但理想地像文本一样,看起来像是黑色div中的一个孔。

渐变为背景, https://i.sstatic.net/0ixos.png” alt =“ note text”>

到目前为止,这是我的CSS

.black {
  overflow: hidden;
  height: 88vh;
  width: 98vw;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #000000;
  /* border-width: 2vh;
  border-style: solid;
  border-image: var(--gradient) 1; */
 }

 .gradient {
  overflow: hidden;
  height: 92vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: var(--gradient);
 }

 .wallText {
  font-weight: 800;
  font-size: 4vh;
  justify-content: space-between;
  color: transparent;
 }

 return (
    <div className='grad'>
      <div className="black">
      <p className="wallText">WALL</p>
      </div>
    </div>
  )

=“ nofollow noreferrer”>

I'm making a personal website. I wanted to add something fun and let people write to my 'wall'. The idea is to have a grandparent div that is a linear gradient, a parent div that is black and text that matches the grandparent div (the part of the gradient that would be under the text. I know I can just give the text the same gradient as the background but id ideally like the text to look as if it is a hole in the black div. Here is the page without text:

Page without text

Here is my CSS so far:

.black {
  overflow: hidden;
  height: 88vh;
  width: 98vw;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #000000;
  /* border-width: 2vh;
  border-style: solid;
  border-image: var(--gradient) 1; */
 }

 .gradient {
  overflow: hidden;
  height: 92vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: var(--gradient);
 }

 .wallText {
  font-weight: 800;
  font-size: 4vh;
  justify-content: space-between;
  color: transparent;
 }

and the JSX:

 return (
    <div className='grad'>
      <div className="black">
      <p className="wallText">WALL</p>
      </div>
    </div>
  )

Thanks in advance for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

止于盛夏 2025-02-17 08:55:16

查看CSS-tricks中的淘汰文字的帖子
在下面使用它是类似于您的片段。

.gradient {
  overflow: hidden;
  height: 92vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(to right, red, red 5%, #fff);
 }
.wall {
  overflow: hidden;
  height: 88vh;
  width: 98vw;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #000000;
  color: transparent;
  
  color: white;
  mix-blend-mode: multiply;
 }
<div class='gradient'>
    <p class="wall">Wall Text</p>
</div>

check out the post for Knockout text from css-tricks
using that below is a snippet similar to yours.

.gradient {
  overflow: hidden;
  height: 92vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(to right, red, red 5%, #fff);
 }
.wall {
  overflow: hidden;
  height: 88vh;
  width: 98vw;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #000000;
  color: transparent;
  
  color: white;
  mix-blend-mode: multiply;
 }
<div class='gradient'>
    <p class="wall">Wall Text</p>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文