CSS Transition with Linear Gradient: A Potential Pitfall
When attempting to add a transition to a button with a CSS linear gradient background, it may exhibit an unexpected lack of effect. This discrepancy stems from the current limitation in transitioning gradients.
Instead of attempting to transition the gradient directly, a workaround involves introducing an additional element:
<code class="css">a.button { background: linear-gradient(top, green, #a5c956); } .button-helper { position: absolute; background: linear-gradient(top, lime, #89af37); transition: opacity 1s linear; } a.button:hover .button-helper { opacity: 1; }</code>
This helper element possesses its own linear gradient and tailored opacity. The transition will toggle the opacity between 0 and 1 on hover, creating the illusion of a gradient transition.
The above is the detailed content of CSS Transition with Linear Gradient: Why Does My Gradient Not Transition?. For more information, please follow other related articles on the PHP Chinese website!