HTML
<div class="container"> <button class="btn">Button</button> </div>
CSS
body { margin: 0; padding: 0; background: #34495e; font-family: sans-serif; } .container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } .btn { text-transform: uppercase; text-decoration: none; letter-spacing: 2px; font-size: 24px; color: #ecf0f1; padding: 20px 44px; outline: none; border: none; border-radius: 40px; text-align: center; box-sizing: border-box; box-shadow: 0 2px 5px rgba(0, 0, 0, .3); background: linear-gradient(90deg, #95a5a6, #2ecc71, #f1c40f, #d35400, #95a5a6); background-size: 200%; } .btn:hover { animation: gradient 4s linear infinite; } @keyframes gradient { 0% { background-position-x: 0; } 100% { background-position-x: 200%; } } .btn::before { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 130px; height: 40px; padding: 20px 44px; border-radius: 40px; z-index: -1; background: linear-gradient(90deg, #95a5a6, #2ecc71, #f1c40f, #d35400, #95a5a6); background-size: 200%; opacity: 0; transition: .5s; } .btn:hover::before { filter: blur(20px); opacity: 1; animation: gradient 4s linear infinite; }
Demo
Description
background-size: 200%;
: 尺寸放大,方便动画渐变
这两个我一般都是一起用,清除原有的边框轮廓
outline: none; border: none;
filter: blur(20px)
: 加上高斯模糊,因为背景虚化是用::before 定位到的,所以这里使用模糊使得背景自然一些
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于