0

.test{
  color: transparent;
  font-size: 50px;
  font-weight: bold;
  transition: 0.5s;
  background-clip: text;
  background: linear-gradient(to right, green, blue);
}
<p class="test">Hello</p>

also when I type background-clip: and the autocomplete options come up for example: border-box, 'text' doesn't come up there at all and I've tried it on Microsoft Edge and Chrome and it still doesn't do anything at all is there any way to fix this?

I tried rearranging the properties in the CSS file and I used a new browser but that still did nothing at all

2 Answers2

2

I think your problem is browser support. After a quick Google search, I found:

The “background-clip: text” is supported in all main browsers with the Webkit prefix, it allows a background image to be clipped by a text element.

So to fix your problem simply add:

-webkit-background-clip: text;

.test {
  color: transparent;
  font-size: 50px;
  font-weight: bold;
  transition: 0.5s;
  background-clip: text;
  background: linear-gradient(to right, green, blue);
  background-clip: text;
  -webkit-background-clip: text;
}
<p class="test">Hello</p>
Ethan
  • 118
  • 1
  • 13
  • thats worked now thanks but do you know why it didnt just work without that? like why cant it just work without it? – Randomguy660 Mar 09 '23 at 20:00
  • ```background-clip``` on its own does work in other browsers that aren't based on WebKit (ie: Firefox). However, ```background-clip``` doesn't work on WebKit-based browsers (ie: Chrome and Safari). Instead, you need to use the ```webkit``` preface. See https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip for more information about ```background-clip``` browser support. – Ethan Mar 09 '23 at 20:10
0

Your CSS code is addressing the name class, but your p element has the test class. Change one so that they match.

Additionally, you may need to add the -webkit-background-clip CSS property for this code to work on Chrome. An example of the code functioning is shown below.

.name {
  background: linear-gradient(to right, green, blue);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;

  font-size: 50px;
  font-weight: bold;
  transition: 0.5s;
}
<p class="name">Hello</p>
Brooke
  • 337
  • 2
  • 8