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

試著忘記壹切 提交于 2019-12-22 04:35:28

问题


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%);
}


回答1:


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>


来源:https://stackoverflow.com/questions/37020910/changing-text-color-on-2-sides-of-diagonal-gradient-line-in-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!