【问题标题】:Is it possible to create a CSS linear gradient for text with specific transition width?是否可以为具有特定过渡宽度的文本创建 CSS 线性渐变?
【发布时间】:2021-04-17 02:28:37
【问题描述】:

我有一个客户要求她的导航栏徽标文本具有 CSS 渐变,从第一种颜色到第二种颜色的过渡非常短,就像她在网上找到的这张图片:

我知道在 CSS 中创建文本过渡的唯一方法是使用类似于以下代码的代码,它会创建一个非常渐进的过渡。

nav.navbar span {
  background: -webkit-linear-gradient(#f9f876, #82f7d6);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

结果文本:

是否可以实现像她在 CSS 中请求文本的效果?还是她只需要向设计师提出要求?

【问题讨论】:

    标签: css colors webkit linear-gradients


    【解决方案1】:

    可以,通过指定起点和终点(例如 40% 和 60%):

    background: linear-gradient(#f9f876 40%, #82f7d6 60%);
    

    body {
      background-color: magenta;
    }
    
    h1 {
      background: linear-gradient(#f9f876 40%, #82f7d6 60%);
      background: -webkit-linear-gradient(#f9f876 40%, #82f7d6 60%);
      background-clip: text;
      -webkit-background-clip: text;
      color: transparent;
      -webkit-text-fill-color: transparent;
    }
    <h1>DOLCE'S DOLLHOUSE</h1>

    【讨论】:

    • 这对我来说非常有效。只需在线性渐变属性中添加起点和终点即可。谢谢!
    猜你喜欢
    • 2011-11-13
    • 2017-09-03
    • 2022-12-15
    • 2018-01-04
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多