按钮图标

精美的纯CSS3滑动开关按钮

阿里云


这是一组使用 CSS3 制作的精美滑动开关按钮特效。这组滑动按钮按 Bootstrap 的情景类来设计,可以适应 5 种不同的场景,以及一种不可用的状态。

HTML 结构

该滑动按钮效果的基本 HTML 结构使用一个<div>元素来包裹一个<input>元素和两个<label>元素。

也想出现在这里?联系我们
创客主机
  1. <div class="switch-box">
  2.   <input id="default" class="switch-box-input" type="checkbox" />
  3.   <label for="default" class="switch-box-slider"></label>
  4.   <label for="default" class="switch-box-label">Default</label>
  5. </div>

CSS 样式

第一个

  1. .switch-box .switch-box-slider {
  2.   position: relative;
  3.   display: inline-block;
  4.   height: 8px;
  5.   width: 32px;
  6.   background: #d5d5d5;
  7.   border-radius: 8px;
  8.   cursor: pointer;
  9.   -webkit-transition: all 0.2s ease;
  10.   transition: all 0.2s ease;
  11. }

.switch-box-slider 元素的::after 伪元素用于制作圆形的滑块。

  1. .switch-box .switch-box-slider:after {
  2.   position: absolute;
  3.   left: -8px;
  4.   top: -8px;
  5.   display: block;
  6.   width: 24px;
  7.   height: 24px;
  8.   border-radius: 50%;
  9.   background: #eeeeee;
  10.   box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.2);
  11.   content: '';
  12.   -webkit-transition: all 0.2s ease;
  13.   transition: all 0.2s ease;
  14. }

当.switch-box-input 元素处于 checked 状态时,.switch-box-slider 的:after 伪元素的 left 属性被修改,圆形滑块被移动。

  1. .switch-box .switch-box-input ~ .switch-box-label {
  2.   margin-left: 8px;
  3. }
  4. .switch-box .switch-box-input:checked ~ .switch-box-slider:after {
  5.   left: 16px;
  6. }

精美的纯 CSS3 滑动开关按钮

已有 572 人购买
  • 482n
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!