Question:
Is there a way to generate gradient text without specifying every letter? For example, something like below:
.rainbow { background-image: linear-gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #2f2),color-stop(0.75, #2f2), color-stop(0.9, #ff2), color-stop(1, #f22) ); background-image: gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #2f2),color-stop(0.75, #2f2), color-stop(0.9, #ff2), color-stop(1, #f22) ); color: transparent; -webkit-background-clip: text; background-clip: text; }
<span class="rainbow">Rainbow text</span>
But not with rainbow colors, rather something like a gradient from white to gray.
Answer:
While the exact syntax for specifying color stops may vary, here's a similar example with a white-to-gray/light blue gradient:
.rainbow2 { background-image: linear-gradient(to right, #E0F8F7, #585858, #fff); color: transparent; -webkit-background-clip: text; background-clip: text; }
<span class="rainbow">Rainbow text</span>
No rainbow text
By adjusting the color stops and their positions, you can create custom gradients for your text without having to hard-code every letter.
The above is the detailed content of Can Gradient Text Be Generated Without Defining Each Letter Individually?. For more information, please follow other related articles on the PHP Chinese website!