I'm using a submit button with a gradient color for the background. I would like to animate that color on hover, though gradient color is not an animatable property. I found a good CSS trick to make this work on an anchor tag using the ::before element, but it doesn't seem to work on the submit button. Below is example code for animating with the anchor. Why does this same code not work when the anchor is replaced with a submit? I think the issue is related to the height and width of the ::before element on the submit button, but can't understand why it doesn't pick up the size of the button. Thoughts?
a {
background: linear-gradient(to bottom, #3ccf2c 40%, #185400 100%);
color: white;
display: inline-block;
padding: 5px;
position: relative;
z-index: 5;
}
a::before {
background: linear-gradient(to bottom, #2d9b21 40%, #123f00 100%);
content: '';
display: block;
height: 100%;
left: 0;
position: absolute;
transition: opacity 0.4s;
top: 0;
opacity: 0;
width: 100%;
z-index: -5;
}
a:hover::before {
opacity: 1;
}
<body>
<a>submit</a>
</body>