0

This doesn't show my hover effects:

<input type="button" class="button" value="Click"> 

This does:

<button class="button">Click</button>

CSS codes work when adding button but. It doesn't work when you add input.

@import url("https://fonts.googleapis.com/css?family=Raleway:300");
* {
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  height: 100vh;
  background: black;
  align-items: center;
  justify-content: center;
}

.button {
  position: relative;
  height: 60px;
  width: 200px;
  border: none;
  outline: none;
  color: white;
  background: #111;
  cursor: pointer;
  border-radius: 5px;
  font-size: 18px;
  font-family: 'Raleway', sans-serif;
}

.button:before {
  position: absolute;
  content: '';
  top: -2px;
  left: -2px;
  height: calc(100% + 4px);
  width: calc(100% + 4px);
  border-radius: 5px;
  z-index: -1;
  opacity: 0;
  filter: blur(5px);
  background: linear-gradient(45deg, #ff0000, #ff7300, #fffb00, #48ff00, #00ffd5, #002bff, #7a00ff, #ff00c8, #ff0000);
  background-size: 400%;
  transition: opacity .3s ease-in-out;
  animation: animate 20s linear infinite;
}

.button:hover:before {
  opacity: 1;
}

.button:hover:active {
  background: none;
}

.button:hover:active:before {
  filter: blur(2px);
}

@keyframes animate {
  0% {
    background-position: 0 0;
  }
  50% {
    background-position: 400% 0;
  }
  100% {
    background-position: 0 0;
  }
}
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8">
  <title>Glowing Button on Hover</title>
</head>

<body>
  <button class="button">Hover Me</button>
  <input type="button" class="button" value="Click">
</body>

</html>
isherwood
  • 58,414
  • 16
  • 114
  • 157

1 Answers1

1

A workaround: Wrap the <input> in a <div class='button'> and modify the .button css to include .button>input as below

@import url("https://fonts.googleapis.com/css?family=Raleway:300");
* {
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  height: 100vh;
  background: black;
  align-items: center;
  justify-content: center;
}

.button,
.button>input {
  position: relative;
  height: 60px;
  width: 200px;
  border: none;
  outline: none;
  color: white;
  background: #111;
  cursor: pointer;
  border-radius: 5px;
  font-size: 18px;
  font-family: 'Raleway', sans-serif;
}

.button:before {
  position: absolute;
  content: '';
  top: -2px;
  left: -2px;
  height: calc(100% + 4px);
  width: calc(100% + 4px);
  border-radius: 5px;
  z-index: -1;
  opacity: 0;
  filter: blur(5px);
  background: linear-gradient(45deg, #ff0000, #ff7300, #fffb00, #48ff00, #00ffd5, #002bff, #7a00ff, #ff00c8, #ff0000);
  background-size: 400%;
  transition: opacity .3s ease-in-out;
  animation: 20s infinite linear animate;
}

.button:hover:before {
  opacity: 1;
}

.button:hover:active {
  background: none;
}

.button:hover:active:before {
  filter: blur(2px);
}

@keyframes animate {
  0% {
    background-position: 0 0;
  }
  50% {
    background-position: 400% 0;
  }
  100% {
    background-position: 0 0;
  }
}
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8">
  <title>Glowing Button on Hover</title>
</head>

<body>
  <button class="button">Hover Me</button>

  <div class="button">
    <input type="button" value="Click">
  </div>
</body>

</html>
fnostro
  • 4,531
  • 1
  • 15
  • 23