实现一个div的背景颜色从左到右慢慢出现

怎样实现一个div的背景颜色从左到右慢慢出现?

  • 在这里为大家介绍伪类 :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>
发布了24 篇原创文章 · 获赞 4 · 访问量 4467

猜你喜欢

转载自blog.csdn.net/Amo__/article/details/93487987
今日推荐