我正在尝试创建一个像这样的纯 CSS 波纹效果: https://codepen.io/finnhvman/pen/jLXKJw
除了我想使用透明白色作为背景颜色以便能够在不同背景上使用按钮。我唯一的问题是,涟漪效应似乎总是错误的方式:不是一个较浅的圆圈展开,点击时背景变亮,展开的圆圈颜色较深。
我的代码是这样的:
.background{
width: 150px;
display: inline-block;
height: 50px;
background: #0066dd;
padding: 20px;
}
.color2{
background: #6600cc;
}
.button{
font-size: 24px;
color: #fff;
padding: 10px;
cursor: pointer;
transition: all 0.8s ease;
background-position: center;
}
.button:hover{
background: rgba(255, 255, 255, 0.15) radial-gradient(circle, transparent 1%, rgba(255, 255, 255, 0.15) 1%) center/15000%;
}
.button:active{
background-color: rgba(255, 255, 255, 0.5);
background-size: 100%;
transition: background 0s;
}
<div class="background">
<span class="button">Button 1</span>
</div>
<div class="background color2">
<span class="button">Button 2</span>
</div>
如何使效果完全相反?单击时,较浅的白色应该从中间开始并向外扩展。
最佳答案
您可以反转 radial-gradient
中的颜色,这是 .button:hover
规则的背景:
.background {
width: 150px;
display: inline-block;
height: 50px;
background: #0066dd;
padding: 20px;
}
.color2 {
background: #6600cc;
}
.button {
font-size: 24px;
color: #fff;
padding: 10px;
cursor: pointer;
transition: all 0.8s ease;
background-position: center;
}
.button:hover {
background: rgba(255, 255, 255, 0.15) radial-gradient(circle, rgba(255, 255, 255, 0.15) 1%, transparent 1%) center/15000%;
}
.button:active {
background-color: rgba(255, 255, 255, 0.5);
background-size: 100%;
transition: background 0s;
}
<div class="background">
<span class="button">Button 1</span>
</div>
<div class="background color2">
<span class="button">Button 2</span>
</div>
关于html - 波纹效果纯css透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58979899/