label+input实现按钮开关切换效果

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.ipt {
display: none;
}
.box {
width: 74px;
height: 30px;
line-height: 30px;
overflow: hidden;
border: 1px solid #eee;
border-radius: 4px;
position: relative;
cursor: pointer;
}
label {display:inline-block;}
.ipt:checked + .box .switch-btn {
left: ;
}
.switch-btn {
position: absolute;
left: -37px;
top: ;
width: 111px;
height: 30px;
transition: all .5s;
}
.switch-btn span{
width: 37px;
height: 30px;
display: block;
text-align: center;
float: left;
font-size: 14px;
}
.on {
background: #52B13C;
color: white;
}
.white {
background: white;
}
.off {
background: #EEEEEE;
}
</style>
</head>
<body>
<p>主要使用label+input来实现改变left的值,下面是核心代码,意思就是<code>选中的input的兄弟节点.box下的.switch-btn元素的left会变成0px(原来是-37px);</code></p>
<pre>
.ipt:checked + .box .switch-btn {
left: ;
}
</pre>
<p>当然要配合transition来实现</p>
<p>下面是效果</p>
<div class="wrap">
<label>
<input class="ipt" type="checkbox" name="" value="">
<div class="box">
<div class="switch-btn">
<span class="on">ON</span>
<span class="white"></span>
<span class="off">OFF</span>
</div>
</div>
</label>
</div>
<p>全部css代码</p>
<pre>
.ipt {
display: none;
}
.box {
width: 74px;
height: 30px;
line-height: 30px;
overflow: hidden;
border: 1px solid #eee;
border-radius: 4px;
position: relative;
cursor: pointer;
}
.ipt:checked + .box .switch-btn {
left: ;
}
.switch-btn {
position: absolute;
left: -37px;
top: ;
width: 111px;
height: 30px;
transition: all .5s;
}
.switch-btn span{
width: 37px;
height: 30px;
display: block;
text-align: center;
float: left;
font-size: 14px;
}
.on {
background: #52B13C;
color: white;
}
.white {
background: white;
}
.off {
background: #EEEEEE;
}
</pre>
</body>
</html>

label+input实现按钮开关切换效果的更多相关文章

  1. label+input实现开关切换效果

    Document 主要使用label+input来实现改变left的值,下面是核心代码,意思就是选中的input的兄弟节点.box下的.switch-btn元素的left会变成0px(原来是-37px ...

  2. 移动端页面a input去除点击效果及pc端切换

    1 手机端页面a button input去除点击效果以及闪屏问题 添加: a, button, input { -webkit-tap-highlight-color: rgba(255, 0, 0 ...

  3. 纯 CSS 利用 label + input 实现选项卡

    clip 属性 用于剪裁绝对定位元素. .class { position:absolute; clip:rect(0px,60px,200px,0px); } scroll-behavior: sm ...

  4. 很实用的HTML5+CSS3注册登录窗体切换效果

    1. [代码]3个很实用的HTML5+CSS3注册登录窗体切换效果 <!DOCTYPE html><!--[if lt IE 7 ]> <html lang=" ...

  5. 用CSS实现Tab页切换效果

    用CSS实现Tab切换效果 最近切一个页面的时候涉及到了一个tab切换的部分,因为不想用js想着能不能用纯CSS的选择器来实现切换效果.搜了一下大致有下面三种写法. 利用:hover选择器 缺点:只有 ...

  6. js实现中文简繁切换效果

    html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  7. Jquery实现图片切换效果(IE,FF,Goole)都可以正常运行

    这里先对标签的样式进行设置(我这里只用了3张图片,可以根据自己的情况,添加) <style type="text/css"> /*展示图片切换的div样式*/ #Sho ...

  8. 【jQuery Demo】图片切换效果整理

    图片的切换效果有很多,比较常见的有水平滚动.垂直滚动.淡入淡出等.我们接下来一一实现这些效果. 1.水平滚动 1) 我们先来实现HTML页面,代码很简单: <div id="conta ...

  9. 100种不同图片切换效果插件pageSwitch

    分享100种不同图片切换效果插件pageSwitch.这是一款适用于全屏切换场景,即一切一屏,并且实现了超过一百种切换效果,支持自定义切页动画.效果图如下: 在线预览   源码下载 实现的代码. ht ...

随机推荐

  1. tensorflow session会话控制

    import tensorflow as tf # create two matrixes matrix1 = tf.constant([[3,3]]) matrix2 = tf.constant([ ...

  2. Django 的认证系统

    Django自带的用户认证 auth 模块 from django.contrib import autu django.contrib.auth 中提供了许多方法, 这里主要介绍其中三个: auth ...

  3. Win10不能直接拖文件/Foxmail不能拖文件解决办法

    在桌面新建一个文本文档   打开文本文档复制下面的文字然后保存. Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\M ...

  4. doxygen+ graphviz 开源工具生成源码调用树的wiki

    当拿到一含有大量代码的工程怎么看?!这时一个好的代码分析工具非常有用,网上有很多开源工具,但资料都参差不齐,偶然发现doxygen+ graphviz这两工具非常棒,使用工具直接生成函数调用链图,帮助 ...

  5. 【IDEA下使用tomcat部署web项目】

    1.IDEA下的WEB项目新建就不说了. 2.配置tomcat:file-->settings-->Build,Execution,Deployment-->Application ...

  6. 飘逸的python - 装饰器的本质

    很多人把装饰器搞的很复杂,其实本质很简单. 首先,什么是装饰器呢?在代码中发现戴着@xxx帽子的,就是装饰器. 那要怎么自己定义一个装饰器呢? 其实任何一个接收一个参数的callable都可以用来做装 ...

  7. 使用 PHPMailer 发送邮件出现诡异bug,间歇性发送失败

    场景 使用PHPMailer的SMTP发送邮件,用的是腾讯企业邮箱 smtp.exmail.qq.com 在邮箱设置里看到配置smtp方法 问题描述 本地windows开发环境发送邮件100%成功 远 ...

  8. k8s 部署应用程序

    k8s相关工具介绍: Kubeadm Kubeadm解决了处理TLS加密配置.部署核心Kubernetes组件和确保其他节点可以轻松地加入集群的问题.生成的集群通过RBAC等机制得到保护. 有关Kub ...

  9. Exadata X2-2 更换 存储节点Flash卡电池(ESM)

    Exadata X2-2中的F20 Flash卡含有电源存储模块ESM(Energy Storage Module ), 也就是我们常说的电池,当主机异常断电时,ESM给Flash模块提供备用电源.实 ...

  10. Git工具详解以及与GitHub的配合使用

    git和Github 概念 git --- 版本控制工具(命令). 工具介绍官方网站:http://git-scm.com 工具下载地址:http://git-scm.com/download/ gi ...