纯CSS自定义动画开关、选择框和单选按钮

纯CSS自定义动画开关、选择框和单选按钮

添加时间:2021-02-27 05:19:02
站长推荐丨赞助论坛,可获取海量资源终身免费下载权限奥!
举报 举报
收藏
预览
附件 附件
  • 模板类型模板类型:复选框
  • 模板颜色模板颜色:入门级
  • 下载积分下载积分:28 米粒
  • 下载权限下载权限:

    赞助会员

一款纯CSS的开关、复选框和单选按钮的动画特效,不只是样式的切换而已,同时还有样式切换的动画效果,非常实用,应用也很广泛,喜欢的童鞋就收下吧。
纯CSS自定义动画开关、选择框和单选按钮
分类:表单代码 > 复选框 难易:入门级

页面的head部分的样式还是比较多的,因为有三种类型的动画特效,代码如下:

.switch label {
  display: block;
  width: 44px;
  height: 16px;
  border-radius: 10px;
  background: rgba(189, 195, 199, 0.5);
  vertical-align: middle;
  position: relative;
  cursor: pointer;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  -webkit-transition: background 350ms ease;
  transition: background 350ms ease;
}
.switch label:before, .switch label:after {
  content: "";
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  -webkit-transition: all 120ms linear;
  transition: all 120ms linear;
}
.switch label:before {
  background: rgba(189, 195, 199, 0.07);
  -webkit-transform: translate3d(0, -50%, 0) scale(0);
          transform: translate3d(0, -50%, 0) scale(0);
}
.switch label:after {
  background: #bdc3c7;
  -webkit-transform: translate3d(0, -50%, 0);
          transform: translate3d(0, -50%, 0);
}
.switch input:checked + label {
  background: rgba(38, 199, 252, 0.6);
}
.switch input:checked + label:before {
  background: rgba(142, 68, 173, 0.07);
  -webkit-transform: translate3d(100%, -50%, 0) scale(1);
          transform: translate3d(100%, -50%, 0) scale(1);
}
.switch input:checked + label:after {
  background: #26c7fc;
  -webkit-transform: translate3d(100%, -50%, 0);
          transform: translate3d(100%, -50%, 0);
}

.checkbox input[type="checkbox"] {
  position: relative;
  margin: 0 10px;
}
.checkbox input[type="checkbox"]:before {
  border: 2px solid transparent;
  content: "";
  cursor: pointer;
  display: block;
  height: 17px;
  position: absolute;
  -webkit-transition: all 200ms linear;
  transition: all 200ms linear;
  width: 17px;
  z-index: 1;
}
.checkbox input[type="checkbox"]:checked:before {
  border-color: #26c7fc;
  border-top-style: none;
  border-right-style: none;
  height: 10px;
  -webkit-transform: rotate(-45deg);
          transform: rotate(-45deg);
}
.checkbox input[type="checkbox"]:after {
  background: #FFFFFF;
  content: "";
  display: block;
  height: 17px;
  position: absolute;
  border: 2px solid rgba(189, 195, 199, 0.5);
  top: 0;
  width: 17px;
  z-index: 0;
}

.radio label {
  display: inline-block;
  cursor: pointer;
}
.radio label:hover .inner {
  -webkit-transform: scale(0.5);
          transform: scale(0.5);
  opacity: 0.5;
}
.radio label input {
  width: 1px;
  height: 1px;
  opacity: 0;
}
.radio label input:checked + .outer .inner {
  -webkit-transform: scale(1);
          transform: scale(1);
  opacity: 1;
}
.radio label input:checked + .outer {
  border: 3px solid #26c7fc;
}
.radio label input:focus + .outer .inner {
  -webkit-transform: scale(1);
          transform: scale(1);
  opacity: 1;
  background-color: #26c7fc;
}
.radio label .outer {
  width: 20px;
  height: 20px;
  display: block;
  float: left;
  margin: 0 5px;
  -webkit-transition: all 150ms linear;
  transition: all 150ms linear;
  border: 3px solid rgba(189, 195, 199, 0.5);
  border-radius: 50%;
  background-color: #fff;
}
.radio label .outer .inner {
  -webkit-transition: all 150ms linear;
  transition: all 150ms linear;
  width: 14px;
  height: 14px;
  -webkit-transform: scale(0);
          transform: scale(0);
  display: block;
  margin: 3px;
  border-radius: 50%;
  background-color: #26c7fc;
  opacity: 0;
}

html, body {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  height: 100%;
  font-family: 'Microsoft YaHei','Lantinghei SC','Open Sans',Arial,'Hiragino Sans GB','STHeiti','WenQuanYi Micro Hei','SimSun',sans-serif;
}
html .item, body .item {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  min-width: 100px;
  min-height: 100px;
  border: 1px solid rgba(189, 195, 199, 0.2);
  margin: 15px;
  padding: 0 10px;
}
html .item div, body .item div {
  margin-top: 20px;
}

页面的body部分结构很容易把握的,三种类型放置在三个div容器里面,代码如下:

<!--开关-->
<div class="item">开关
  <div class="switch">
    <input id="switch" type="checkbox" hidden="hidden"/>
    <label for="switch"></label>
  </div>
</div>
<!--选择框-->
<div class="item">选择框
  <div class="checkbox">
    <input type="checkbox" name="checkbox" checked="checked"/>
    <input type="checkbox" name="checkbox"/>
  </div>
</div>
<!--单选按钮-->
<div class="item">单选按钮
  <div class="radio">
    <label for="radio1">
      <input id="radio1" type="radio" name="radio" checked="checked"/><span class="outer"><span class="inner"></span></span>
    </label>
    <label for="radio2">
      <input id="radio2" type="radio" name="radio"/><span class="outer"><span class="inner"></span></span>
    </label>
  </div>
</div>
相关内容推荐
资源求助发帖
查看更多发帖

*

回帖描述:

*

链接类型:

*

下载链接:

密码:
发帖规则:回帖内容为会员之间的私信,普通网友无法查看。
免责声明:回帖中提供的链接内容仅供会员之间学习参考使用,获取内容后请在法律法规范围内使用。回帖提供的内容应符合法律法规要求,不得违反法律法律的要求。
站点权责:回帖内容如违反法律法规,站点有权封停账号使用权利。对用户举报的内容,站点有责任及时删除违规内容。
热点内容推荐
标题:纯CSS自定义动画开关、选择框和单选按钮

*

描述:
平均回复时间:3-10分钟
规则介绍:悬赏寻求论坛网友分享资源,站点对分享内容的准确性,合法性,版权等没有足够的监管能力。如果您发现资源不正确,无法使用,不符合法律法律等情况,您可以直接举报资源。站长将尽快核实您的举报,并根据情况,采取封号,退换米粒等处理。

*

回帖描述:

*

链接类型:

*

阅读权限:

*

下载链接:

密码:
发帖规则:回帖内容为会员之间的私信,普通网友无法查看。
免责声明:回帖中提供的链接内容仅供会员之间学习参考使用,获取内容后请在法律法规范围内使用。回帖提供的内容应符合法律法规要求,不得违反法律法律的要求。
站点权责:回帖内容如违反法律法规,站点有权封停账号使用权利。对用户举报的内容,站点有责任及时删除违规内容。
  • 背景波浪
  • 背景波浪
  • 波浪
  • 波浪
客服
在线咨询
周一 至 周日 9:00 ~ 22:00
QQ:1326974360
微信:juyoubuluo6688
客服热线
18205485173
工作日 9:00 ~ 18:00
微信扫码咨询
客户服务
欢迎咨询服务
咨询量较多时,请耐心等待
社群

关注公众号

获取更多资讯

扫码进群(QQ)

与更多大牛交流沟通

0.099323s