The Problem
Well … i don’t know if this is even possible. I have a wonderful menu with a gradient and their child elements with transparent background-color and color white: https://nimb.ws/o5xWlZ
In the hover, i want to make the background-color of this child element color white and the color text make it transparent for show that part of gradient.
What I Have Tried
My first reaction was:
child-element{background-color:#fff;color:transparent}
And you can imagine the results( SPOILER: https://nimb.ws/TNrCKJ ) … only white in the button.
Then, i think to apply a box-shadow …
child-element{-webkit-box-shadow: inset 0px 0px 300px 200px rgba(255,255,255,1);-moz-box-shadow: inset 0px 0px 300px 200px rgba(255,255,255,1);box-shadow: inset 0px 0px 300px 200px rgba(255,255,255,1);}
And wel.. searching and searching … doesn’t find anything … so, here i am.
The Code
This is the HTML, i can’t editing so much, because is a dynamic <ul>
in a .tpl
<div id="block_top_menu" class="full-width here-is-the-gradient">
<ul class="sf-menu transparent">
<li class="menu-li category transparent"><a href="/257-productos-medicos" title="Productos Médicos">Productos Médicos</a></li>
... others li elements ...
</ul>
</div>
And this is the CSS
#block_top_menu{
background:#6aa447;background:-moz-linear-gradient(45deg,#6aa447 0%,#4d81bd 90%);
background:-webkit-gradient(left top,right top,color-stop(0%,#6aa447),color-stop(100%,#4d81bd));
background:-webkit-linear-gradient(45deg,#6aa447 0%,#4d81bd 90%);
background:-o-linear-gradient(45deg,#6aa447 0%,#4d81bd 90%);
background:-ms-linear-gradient(45deg,#6aa447 0%,#4d81bd 90%);
background:linear-gradient(to right,#6aa447 0%,#4d81bd 90%);
filter:progid:DXImageTransform.Microsoft.gradient( startColorstr='#6aa447',endColorstr='#4d81bd',GradientType=1);otherthings
}
.sf-menu{
background:transparent;
...otherthings...
}
...
.sf-menu > li > a{
border:none;color:#fff;
font: 500 18px Oswald;
padding:10px 5px;
text-transform:none;
}
.sf-menu > li > a:hover {
/* What do I put here? */
}
An example:
Like to fill text with an image as in Photoshop:
Thanks you very much for the time 🙂
3
Answers
Finally
After searching it with differents words for the same problem, I found an interesting article in CSS-Tricks about this. Here i found this codepen from Richard.
Then, complementing this technique with my html and css, I have obtained the expected result:
You can see it in a Full Page View at Codepen
Thanks a lot to everyone who reads me and suggest me a solution or trick.
Greetings, V.Alex.
Use the descendant combinator? Like below?
https://www.sitepoint.com/masking-in-the-browser-with-css-and-svg/
you will need to create a vector mask using SVG’s.
warning:
css mask is not currently supported by IE
https://caniuse.com/#search=mask
codepen example:
https://codepen.io/antonietta/pen/zqpBEg