核心属性
-webkit-appearance: none 消除元素的默认外观
:hover/:checked + transition + background 背景颜色的过渡效果
text-align: center + line-height: 40px 对勾符号水平垂直居中显示
animation + width + height + opacity 按钮状态切换的动画效果
提示:::after伪元素实现的动画的中心点与单选多选按钮的中心点是对齐的,对齐的方法就是将伪元素上移和左移80px的距离,这个距离是通过200px ÷ 2 - 40px ÷ 2 = 80px计算得出的。
-
<div class="container">
-
<div>
-
<label>
-
<input type="checkbox" class="option-input checkbox" checked />
-
选项一
-
</label>
-
<label>
-
<input type="checkbox" class="option-input checkbox" />
-
选项二
-
</label>
-
<label>
-
<input type="checkbox" class="option-input checkbox" />
-
选项三
-
</label>
-
</div>
-
<div>
-
<label>
-
<input type="radio" class="option-input radio" name="example" checked />
-
选项一
-
</label>
-
<label>
-
<input type="radio" class="option-input radio" name="example" />
-
选项二
-
</label>
-
<label>
-
<input type="radio" class="option-input radio" name="example" />
-
选项三
-
</label>
-
</div>
-
</div>
-
body { -
color: #9faab7;
-
background: #e8ebee;
-
}
-
body div { -
padding: 1rem;
-
}
-
body label { -
display: block;
-
line-height: 40px;
-
}
-
.option-input { -
position: relative;
-
display: inline-block;
-
top: 13.33333px;
-
height: 40px;
-
width: 40px;
-
margin-right: 0.5rem;
-
color: #fff;
-
background: #cbd1d8;
-
outline: none;
-
cursor: pointer;
-
-webkit-appearance: none;
-
transition: all 0.15s ease-out 0s;
-
z-index: 1;
-
}
-
.option-input:hover { -
background: #9faab7;
-
}
-
.option-input:checked { -
background: #40e0d0;
-
}
-
.option-input:checked::before { -
content: '✔';
-
position: absolute;
-
display: inline-block;
-
height: 40px;
-
width: 40px;
-
font-size: 26.66667px;
-
text-align: center;
-
line-height: 40px;
-
}
-
.option-input:checked::after { -
content: '';
-
position: relative;
-
background: #40e0d0;
-
display: block;
-
animation: click-wave 0.65s;
-
}
-
@keyframes click-wave { -
0% { -
height: 40px;
-
width: 40px;
-
opacity: 0.35;
-
}
-
100% { -
height: 200px;
-
width: 200px;
-
margin-left: -80px;
-
margin-top: -80px;
-
opacity: 0;
-
}
-
}
-
.option-input.radio { -
border-radius: 50%;
-
}
-
.option-input.radio::after { -
border-radius: 50%;
-
}
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
JAVA 2核心技术 卷Ⅰ
[美] 霍斯特曼、[美] 科奈尔 / 叶乃文、邝劲筠 等 / 机械工业出版社 / 2006-5 / 88.00元
本书是Java技术经典参考书,多年畅销不衰,第7版在保留以前版本风格的基础上,涵盖Java2开发平台标准版J2SE5.0的基础知识,主要内容包括面各对象程序设计、反射与代理、接口与内部类、事件监听器模型、使用Swing UI工具箱进行图形用户界面设计,异常处理、流输入/输出和对象序列化、泛型程序设计等。 本书内容翔实、深入浅出,附有大量程序实例,极具实用价值,是Java初学者和Java程序员......一起来看看 《JAVA 2核心技术 卷Ⅰ》 这本书的介绍吧!
JSON 在线解析
在线 JSON 格式化工具
RGB CMYK 转换工具
RGB CMYK 互转工具