Can somebody help me to understand how is created the text in this website?
Basically, what I need is the text colour to be the same as the gradient colour(the background colour of the predecessor div) on a white background.
Thank you!!
Can somebody help me to understand how is created the text in this website?
Basically, what I need is the text colour to be the same as the gradient colour(the background colour of the predecessor div) on a white background.
Thank you!!
This isn't my best work because it relies on hardcoded positions and background-sizes, but it does work as a quick and dirty solution.
The text appears to be clipped from the surrounding black rectangles.
In fact each span
of text has its own background, positioned such that it aligns perfectly with the gradient background of the h1
beneath.
h1 {
position: relative;
display: block;
width: 200px;
height: 200px;
background-image: linear-gradient(
red,orange,yellow,green,blue,indigo,violet
);
}
h1 span {
display: block;
position: relative;
top: 10px;
width: 180px;
height: 50px;
margin: 20px 10px;
line-height: 50px;
font-size: 40px;
text-align: center;
background-color: rgb(0, 0, 0);
}
h1 span::after {
position: absolute;
top: 0;
left: 0;
width: 100%;
background-image: linear-gradient(
red,orange,yellow,green,blue,indigo,violet
);
background-size: 200px 200px;
background-clip: text;
-webkit-text-fill-color: transparent;
}
h1 span:nth-of-type(1)::after {
content: 'Example';
background-position: -20px -20px;
}
h1 span:nth-of-type(2)::after {
content: 'Text';
background-position: -20px -80px;
}
<h1>
<span>Example</span>
<span>Text</span>
</h1>