Search code examples
htmlcsshovercss-transitions

Problem with a "hover" in one input[type="submit"]


Can anyone help me understand why my CSS styling is not being applied correctly to the input?

.html code .CSS styles

I need to achieve a smooth transition with the CSS styles, but for some reason they are not being applied correctly.

<input type="submit" value="Submit" />

input[type="submit"] {
  background: #fff; 
  color: #4741d7;
  border: 2px solid #4741d7; 
  padding: 16px 20px;
  border-radius: 3px;
  position: relative;
  z-index: 1;
  overflow: hidden;
  display: inline-block;
  font-size: large;
  letter-spacing: 12px;
}
input[type="submit"]:hover {
  color: #fff;
}
input[type="submit"]::after {
  content: "";
  background-color: #4741d7; 
  position: absolute;
  z-index: -1;
  padding: 16px 20px;
  display: block;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  transform: scale(0, 0) rotate(-180deg);
  transition: all 0.3s ease;
}
input[type="submit"]:hover::after {
  transition: all 0.3s ease-out;
  transform: scale(1, 1) rotate(0deg);
}

Solution

  • add transition: all 0.3s ease to input[type="submit"] and remove it from input[type="submit"]::after and input[type="submit"]:hover::after