Achieve a div background color occurs slowly from left to right

How to achieve a div background colors appear slowly from left to right?

  • Here to introduce pseudo-class: after
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
   
   .btn button {
      position: relative;
    }

    .btn button::after {
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      right: 0;
      transition: .3s;
      opacity: .3;
      background: #000;
      transform-origin: left;
      transform: scaleX(0);
    }

    .btn button:hover::after {
      transform: scaleX(1);
    }
    .btn button{
        background-color: red;
        width: 200px;
        height: 40px;
        border: none;
        outline: none;
        cursor: pointer;
        color: white;
    }
  </style>
</head>
<body>
  <div class="btn">
    <button>按钮</button>
</div>
</html>
Published 24 original articles · won praise 4 · Views 4467

Guess you like

Origin blog.csdn.net/Amo__/article/details/93487987