Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing text color on 2 sides of diagonal gradient line in html

Any idea on how to change text color for 2 parts of gradient line? For example here if I want the blue part of the text ('s', 'o' and a part of 'm') to be black?

.button{
   background: linear-gradient(140deg, #00C9FF 35%, transparent 35%);
}

enter image description here

like image 813
Boltosaurus Avatar asked May 04 '16 07:05

Boltosaurus


People also ask

How do you color text a gradient in HTML?

Step 1: Apply a basic background to the body tag and align the text to center of the page. Step 2: Do some basic styling like font-size and family etc. Step 3: Apply the linear gradient property with any colors of your choice.

How do I change the font color of a gradient?

To add a gradient overlay to a text element, we need to set three different CSS properties to the text we want to style: background-image: <gradient> background-clip: text. text-fill-color: transparent.

What is the required number of colors to produce a gradient effect?

To create the most basic type of gradient, all you need is to specify two colors. These are called color stops. You must have at least two, but you can have as many as you want.

Which of the following CSS gradient functions sets the direction and colors of a gradient that fades from one color to the next in a straight line?

Which of the following CSS Gradient Functions sets the direction and colors of a gradient that fades from one color to the next in a straight line? Explanation: Self-explainatory. 2.


1 Answers

You can do it wrapping the text in a <p> tag and setting a linear-gradient to this tag.

button{
   background: linear-gradient(140deg, #00C9FF 35%, transparent 35%);
   color: white;
   font-size: 30px;
}

p{
  margin: 0;
  font-size: 50px;
  background: -webkit-linear-gradient(130deg, red 65%, black 15%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
<button type="button"><p>some long text</p></button>
like image 167
Francisco Romero Avatar answered Nov 04 '22 14:11

Francisco Romero