I have a navigation bar with a gradient background, a <nav>
with a list of links.
When a user is on a certain page, I style the link and list item corresponding to that page differently. What I can't figure out, however, is how to make the text transparent in such a way that it looks exactly like a cutout into the <nav>
gradient—so that the background of the parent <li>
is clear over the text).
I know from answers like this that the protocol is to specify
background: url("image");
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
and position the image accordingly so it appears to line up with the background.
How can I adjust the link's gradient so it appears to be in line with the <nav>
's? Alternatively, is it possible to make the text transparent without specifying a background?
nav {
background:linear-gradient(to left, black, red, white);
height: 100px;
vertical-align: center;
maring: 0;
line-height: 100px;
font-size: 20px;
}
li {
display: inline;
padding: 20px;
}
li.selected {
background-color: white;
}
li.selected a {
background: linear-gradient(to left, black, red, white);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
}
ul {
list-style: none;
}
<nav>
<ul>
<li><a>A</a></li>
<li class="selected">
<a>
B
</a>
</li>
<li><a>C</a></li>
</ul>
</nav>