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. 27、BLASTN的参数

    转载:http://blog.sina.com.cn/s/blog_5ecfd9d90100ksui.html http://www.docin.com/p-704735699.html 与之前的bl ...

  2. Spring入门第五课

    集合属性 在Spring中可以通过一组内置的xml标签(如:<list>,<set>,<map>)来配置集合属性. 配置java.util.List类型的属性,需要 ...

  3. rest framework 权限

    一.权限示例 需求:不同的用户类型有不同的权限 普通用户:只能查看个人信息相关,序号:1 VIP 用户:只能查看个人信息相关,序号:2 SVIP 用户:查看订单相关信息,序号:3 1.新建 app/u ...

  4. ASP.NET jquery 获取服务器控件ID

    一般方法: jQuery("#txtUserName").val(); 如果页面加载了母版页或者自定义控件:该页面的ID有可能会被篡改(可能是因为避免控件ID冲突的机制),因此强烈 ...

  5. api接口访问限制

    1.场景描述 在日常开发接口的时候,尤其是restfull接口,肯定会考虑安全或者是做一些自定义的限制,用来界定并维护代码.那么,我们都会采用什么方法那?通常来讲,我们可以通过session的形式,以 ...

  6. OpenStack虚机状态变化图解

    对官网上内容的一个翻译,方便自己以后查找资料用 The following diagrams and tables show the required virtual machine (VM) sta ...

  7. 《H5+移动应用实战开发》已出版

    <H5+移动应用实战开发>终于出版了,最近在忙着Vue和Webpack相关的前端书籍写稿.本书面向的读者为:从后端转前端,或零基础开始学习移动端开发的人.前后端完全分离的开发方式越来越成为 ...

  8. css3旋转立方体-_-

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  9. 安装篇:MySQL系列之一

    环境:CentOS6.9系统安装MariaDB-10.2.15 一.yum包管理器安装MariaDB-server ​ 1)配置yum源(MariaDB官方源) [root@centos6 ~]# v ...

  10. C 语言实例 - 计算一个数的 n 次方

    C 语言实例 - 计算一个数的 n 次方 计算一个数的 n 次方,例如: ,其中 为基数, 为指数. 实例 - 使用 while #include <stdio.h> int main() ...