CSS实现鼠标移上去按钮表面光影划过特效
初始状态
鼠标移上去时,光影表面掠过
代码如下
html部分
<header style="text-align: center;"> <h1 class="btn">标题</h1> </header>
css部分
.btn { display: inline-block; width: 140px; height: 48px; border: 1px solid #fff; background: #000000; color: #fff; text-align: center; cursor: pointer; font-size: 15px; box-sizing: border-box; line-height: 46px; transition: all .3s; -webkit-transition: all .3s; border-radius: 24px; margin-top: 25px } .btn { position: relative; overflow: hidden } .btn:after { content: ""; position: absolute; left: -120%; top: 0; width: 100%; height: 100%; background-image: -webkit-linear-gradient(0deg, rgba(255,255,255,0), rgba(255,255,255,0.5), rgba(255,255,255,0)); transform: skewx(-25deg); -webkit-transform: skewx(-25deg) } .btn:hover:after { transition: all .5s ease; left: 100% }
看效果如下
标题