I'm trying to create a layout in which some letters are transparent with a white background behind them, but the transparency shows all the way through to a gradient background several levels up the HTML hierarchy. Basically, I'm trying to achieve something like the following:
Here's my current HTML and CSS:
.header {
background-image: linear-gradient(135deg, #2121CC, #1E0674);
}
.header>div {
align-items: center;
display: flex;
justify-content: space-between;
margin: auto;
max-width: 100rem;
padding: 1rem 2rem;
}
.header>div>h1 {
display: flex;
}
.header>div>h1>span {
background: #FFF;
color: transparent;
display: block;
margin-right: 1rem;
-webkit-text-fill-color: transparent;
}
<div class="header">
<div>
<h1>
<span>A</span>
<span>B</span>
</h1>
</div>
</div>
I was referencing the following CSS Tricks article on how to do this:
https://css-tricks.com/how-to-do-knockout-text/
But the issue in my case seems to be that I want the text to be transparent and show through the white background all the way to the .header
element three levels up the HTML hierarchy.
Is this possible with just CSS, and if so, how? I've tried everything I can think of to no avail. Thank you.
Edit: It's worth mentioning that the CSS Tricks article uses the -webkit-background-clip: text;
property, but when I add that to my CSS, it doesn't change anything and it's crossed out when you inspect the corresponding elements in the browser. In other words, I don't think it's supported and actually does anything anymore (I could be wrong).