CSS linear gradient transparency misbehaving only in Safari

前端 未结 1 1873
天命终不由人
天命终不由人 2020-12-10 02:33

Something really strange is happening in Safari. I\'m doing a simple gradient overlay to do a text fade effect. It works fine in Firefox and Chrome, but not Safari, which I

相关标签:
1条回答
  • 2020-12-10 02:48

    Instead of:

    background: linear-gradient(to top, white, transparent);
    

    Try setting your transparent to an rgba color value. For example:

    background: linear-gradient(to top, white, rgba(255,255,255,0));
    

    In other words, the rgb value of both colors should match. For example:

    background: linear-gradient(to top, red, rgba(255,0,0,0));
    

    As defined by the w3c spec, transparent is black transparent (rgba(0,0,0,0)). That means that when you are in the middle of the transition, some black should appear.

    The color seen in Safari is the correct one, as per the specs.

    0 讨论(0)
提交回复
热议问题