如上图所示的图片,如何通过css实现呢?

下面咱们慢慢尝试:

html:
    <div class="togglePosition">
<label class="toggle">
<input type="checkbox">
<div class="track">
<div class="handle"></div>
</div>
</label>
</div>

css:

<style  type="text/css">
.toggle {position: relative; display: inline-block; pointer-events: auto; margin: -5px; padding: 5px; }
.toggle input:checked + .track {border-color: #4AA8FF; background-color: #4AA8FF; }
.toggle.dragging .handle {background-color: #f2f2f2 !important; }
.toggle input {display: none; }
/* the track appearance when the toggle is "off" */
.toggle .track {
-webkit-transition-timing-function: ease-in-out;
transition-timing-function: ease-in-out;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-property: background-color, border;
transition-property: background-color, border;
display: inline-block;
box-sizing: border-box;
width: 51px;
height: 31px;
border: solid 2px #e6e6e6;
border-radius: 20px;
background-color: #fff;
content: ' ';
cursor: pointer;
pointer-events: none; } /* Fix to avoid background color bleeding */
/* (occurred on (at least) Android 4.2, Asus MeMO Pad HD7 ME173X) */
.platform-android4_2 .toggle .track {-webkit-background-clip: padding-box; } /* the handle (circle) thats inside the toggle's track area */
/* also the handle's appearance when it is "off" */
.toggle .handle {
-webkit-transition: 0.3s cubic-bezier(0, 1.1, 1, 1.1);
transition: 0.3s cubic-bezier(0, 1.1, 1, 1.1);
-webkit-transition-property: background-color, transform;
transition-property: background-color, transform;
position: absolute;
display: block;
width: 27px;
height: 27px;
border-radius: 27px;
background-color: #fff;
top: 7px;
left: 7px;
box-shadow: 0 2px 7px rgba(0, 0, 0, 0.35), 0 1px 1px rgba(0, 0, 0, 0.15); }
.toggle .handle:before {position: absolute; top: -4px; left: -21.5px; padding: 18.5px 34px; content: " "; } .toggle input:checked + .track .handle {-webkit-transform: translate3d(20px, 0, 0); transform: translate3d(20px, 0, 0); background-color: #fff; }
.togglePosition{height: 20px; width: 33px; display: inline-block;}
.toggle .track{width: 46px; height: 30px; border: solid 2px #e6e6e6; border-radius: 20px; }
.toggle .handle{width: 28px; height: 28px; border-radius: 18px; background-color: #fff; top: 6px; left: 3px;}
.toggle{margin: -5px; padding: 5px;}
</style>

把上面的代码放入你的html文件动手试试吧,可能不是非常完美,但我相信有了上面的基础你肯定会做出相应的改动实现自己想要的理想的效果的……

二十、滑动开关css的更多相关文章

  1. 整理一下CSS最容易躺枪的二十规则,大家能躺中几条?

    整理一下CSS最容易躺枪的二十规则,大家能躺中几条? 转载:API中文网 一.float:left/right 或者 position: absolute 后还写上 display:block? 二. ...

  2. WCF学习之旅—实现支持REST客户端应用(二十四)

    WCF学习之旅—实现REST服务(二十二) WCF学习之旅—实现支持REST服务端应用(二十三) 在上二篇文章中简单介绍了一下RestFul与WCF支持RestFul所提供的方法,及创建一个支持RES ...

  3. 无废话ExtJs 入门教程二十[数据交互:AJAX]

    无废话ExtJs 入门教程二十[数据交互:AJAX] extjs技术交流,欢迎加群(521711109) 1.代码如下: 1 <!DOCTYPE html PUBLIC "-//W3C ...

  4. Bootstrap <基础二十九>面板(Panels)

    Bootstrap 面板(Panels).面板组件用于把 DOM 组件插入到一个盒子中.创建一个基本的面板,只需要向 <div> 元素添加 class .panel 和 class .pa ...

  5. Bootstrap <基础二十八>列表组

    列表组.列表组件用于以列表形式呈现复杂的和自定义的内容.创建一个基本的列表组的步骤如下: 向元素 <ul> 添加 class .list-group. 向 <li> 添加 cl ...

  6. Bootstrap <基础二十六>进度条

    Bootstrap 进度条.在本教程中,你将看到如何使用 Bootstrap 创建加载.重定向或动作状态的进度条. Bootstrap 进度条使用 CSS3 过渡和动画来获得该效果.Internet ...

  7. Bootstrap <基础二十五>警告(Alerts)

    警告(Alerts)以及 Bootstrap 所提供的用于警告的 class.警告(Alerts)向用户提供了一种定义消息样式的方式.它们为典型的用户操作提供了上下文信息反馈. 您可以为警告框添加一个 ...

  8. Bootstrap<基础二十四> 缩略图

    Bootstrap 缩略图.大多数站点都需要在网格中布局图像.视频.文本等.Bootstrap 通过缩略图为此提供了一种简便的方式.使用 Bootstrap 创建缩略图的步骤如下: 在图像周围添加带有 ...

  9. Bootstrap <基础二十二>超大屏幕(Jumbotron)

    Bootstrap 支持的另一个特性,超大屏幕(Jumbotron).顾名思义该组件可以增加标题的大小,并为登陆页面内容添加更多的外边距(margin).使用超大屏幕(Jumbotron)的步骤如下: ...

  10. Bootstrap<基础二十> 标签

    Bootstrap 标签.标签可用于计数.提示或页面上其他的标记显示.使用 class .label 来显示标签,如下面的实例所示: <!DOCTYPE html> <html> ...

随机推荐

  1. 博客主题皮肤探索-GitHub和jsdelivr的使用

    有个前言 本萌并不会前端相关的知识,一切都是自己慢慢摸索出来的,如果存在代码方面的不足,请尽快告诉我~~~ 使用一个主题 目前我博客使用是 https://www.cnblogs.com/bndong ...

  2. vue.js学习笔记(一)——vue-cli项目的目录结构

    vue.js是一套构建用户界面的渐进式框架.vue采用自底向上增量开发的设计.vue的核心库只关心视图层,非常容易学习,非常容易与其它库和已有项目整合.vue完全有能力驱动采用单文件组件和vue生态系 ...

  3. EPC sequence

    nps-epc-term-2.7.0 eNodeB: /root/b2b/eutran/01/bin ./clean_log.sh ./set_ip.sh [root@CEN6- bin]# ./cl ...

  4. [转] 打造基于CentOS7的xfce最简工作环境[转自smstong,在此记录一下]

    [From]https://blog.csdn.net/hejianlz/article/details/78976013 3 安装步骤 3.1 执行CentOS7 最小安装 去官网下载CentOS- ...

  5. Windows与linux添加用户命令

    Windows 查看当前存在用户: net user 查看当前用户组: net localgroup 添加用户(以添加用户test密码test1234为例): net user test test12 ...

  6. android面试注意点

    Java 基础知识 面向对象的基本思想 Object类相关:Object类的几个关键函数.String涉及到的常量池概念,序列化 & 反序列化. 重要关键字:final.static. 内部类 ...

  7. sencha touch dataview 中添加 button 等复杂布局并添加监听事件

    config 中的属性默认都会自动生成   getter   setter  applier  updater 四个方法. applier 在调用  setter 时被调用, updater 在属性值 ...

  8. Android创建定时和周期任务

    问题:应用需要按时执行某个操作,例如定时更新UI. 解决方案:使用Handler提供的定时操作功能.通过Handler,可以在指定的时间或是指定的延时后执行操作. 下面看一个在TextView中显示当 ...

  9. 为easyui添加多条件验证

    easyui的验证框架,validatebox不能有效的支持多个条件的验证,比如中文用户名,既要验证其是中文,又要验证其长度不超过6位时便显得很繁琐,需要反复的为easyui添加验证规则. 在此实现一 ...

  10. iostat命令——监控系统设备的IO负载情况

    iostat命令的安装 #yum install sysstat iostat常见选项 -t   输出数据时打印搜集数据的时间 -m  输出的数据以MB为单位 -d  显示磁盘的统计信息 # iost ...