Gradient border button 1

by jwerre

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
<button class="gradient-border">
Click Here
</button>

CSS

.gradient-border {

  display: flex;
  align-items: center;
  margin: auto;
  cursor: pointer;

  position: relative;
  padding: 1rem 2em;
  box-sizing: border-box;

  color: black;
  background: tansparent;
  background-clip: padding-box;
  /* !importanté */
  border: solid 2px transparent;
  /* !importanté */
  border-radius: 1em;

  &:before, 
  &:after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: -2px;
    /* !importanté */
    border-radius: inherit;
  }

  &:before {
    background: linear-gradient(to right, red, orange);
    z-index: -1;
    transition: opacity 0.5s linear;
    opacity: 0;
  }

  &:after {
  		    z-index: -2;
      background: linear-gradient(to right, blue, purple);
  }

  &:hover {
    &:before {
	  opacity: 1;
    }
  }
}