如上图所示的图片,如何通过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. C#集合之栈

    栈(Stack)和队列是非常类似的一个容器,只是栈是一个后进先出(LIFO)的容器. 栈用Push()方法在栈中添加元素,用Pop()方法获取最近添加的一个元素: Stack<T>与Que ...

  2. J15W-J45W全铜质截止阀厂家,J15W-J45W全铜质截止阀价格 - 专题栏目 - 无极资讯网

    无极资讯网 首页 最新资讯 最新图集 最新标签   搜索 J15W-J45W全铜质截止阀 无极资讯网精心为您挑选了(J15W-J45W全铜质截止阀)信息,其中包含了(J15W-J45W全铜质截止阀)厂 ...

  3. ant.design初探

    第一部分: 前言 推荐网站: https://ant.design/docs/spec/introduce-cn ant.design是基于react开发的一个解放ui和前端的工具,它提供了一致的设计 ...

  4. orcale 之函数

    我们知道存储过程的调用是一条 PL/SQL 语句.那么对于一些表达式我们用什么呢?这里函数的功能就会体现出来了. 函数和过程在创建方式上有很多的类似地方,也是编译后放入内存中以供用户使用,只不过函数调 ...

  5. 我java学习时的模样(一)

    学会敲键盘,能够实现盲打 程序员写代码,是通过键盘将程序输入到编辑器中,而码子的高效,能够让自己的思路更流畅一些.如果想从事IT工作,那面打字就必须得会,并且,如果还一个一个字母去找,上司就会认为是一 ...

  6. div+css 制作表格

    <div class="table"> <h2 class="table-caption">花名册:</h2> <di ...

  7. python中文分词工具——结巴分词

    传送门: http://www.iteye.com/news/26184-jieba

  8. 有向图和无向图的数组C++实现

    源码:https://github.com/cjy513203427/C_Program_Base/tree/master/55.%E5%9B%BE 结点类Noded.h 不需要存储索引 #pragm ...

  9. [PY3]——找出一个序列中出现次数最多的元素/collections.Counter 类的用法

    问题 怎样找出一个序列中出现次数最多的元素呢? 解决方案 collections.Counter 类就是专门为这类问题而设计的, 它甚至有一个有用的 most_common() 方法直接给了你答案 c ...

  10. Codeforces 543E. Listening to Music

    Description 题面 Solution 分块套分块,分别对时间和位置进行分块 差不多是一个定期保存信息的方法 对于询问我们不妨求出 \(>=x\) 的答案,然后用 \(m-(>=x ...