1

Can somebody help me to understand how is created the text in this website? enter image description here

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!!

Vlad Pana
  • 157
  • 1
  • 7

1 Answers1

0

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>
Rounin
  • 27,134
  • 9
  • 83
  • 108
  • You can work around having to position the background by positioning the text absolutely, as [is done](https://jsfiddle.net/NT7z7/11/) in the solution [linked by OP](//stackoverflow.com/questions/43574648/i-need-to-write-with-transparent-text-on-a-gradient-background-colour#comment74199897_43574648). – Just a student Apr 24 '17 at 12:05