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. Luogu 2668 [NOIP2015]斗地主

    打牌技术不精,没有把$A$放在顺子里面搜,WA了好长时间. 盗用大佬的一张图: 当时自己搜的时候没有把四张牌拆成三带一等情况. 然后还有一点就是四张三张都出完之后直接数一数剩下的一张两张牌还要多少次出 ...

  2. HDU 3966 Aragorn's Story (简单树链剖分)

    题意:给一棵树,并给定各个点权的值,然后有3种操作: I C1 C2 K: 把C1与C2的路径上的所有点权值加上K D C1 C2 K:把C1与C2的路径上的所有点权值减去K Q C:查询节点编号为C ...

  3. 39、生鲜电商平台-redis缓存在商品中的设计与架构

    说明:Java开源生鲜电商平台-redis缓存在商品中的设计与架构. 1. 各种计数,商品维度计数和用户维度计数 说起电商,肯定离不开商品,而附带商品有各种计数(喜欢数,评论数,鉴定数,浏览数,etc ...

  4. Python开发【第五篇】:函数

    1. 函数   函数是组织好的,可重复使用的,用来实现单一,或相关功能的代码块.   函数分为 Python 程序内置函数,用户自定义的函数.将代码定义为函数,有如下好处: 代码重用(某个特定功能复用 ...

  5. rowid去重(转)

    实际应用场景:数据去重--当多条记录主键相同或者多条记录完全一致时,只需要留下一条记录 delete from bal_acctbook_info where rowid not in (select ...

  6. vue里的tab标签

    <template> <div class="Test2"> <div class="tabs_wrap" v-model=&qu ...

  7. P3379 【模板】最近公共祖先(LCA)(倍增)

    这题有毒!!!!!!!!!! TM我重新打的板子,然而...... 5分钟打完 debug两小时 我的写法常数太大了 每次DFS都要For去更新F 最后写了快读才A 改: 只处理f[i][0] dfs ...

  8. Git/Bitbucket Workflow

    中文 http://blog.jobbole.com/76843/ 英文 https://www.atlassian.com/git/tutorials/comparing-workflows#cen ...

  9. ELK(+Redis)-开源实时日志分析平台

    ################################################################################################### ...

  10. 洛谷P2574 XOR的艺术

    题目描述 \(AKN\)觉得第一题太水了,不屑于写第一题,所以他又玩起了新的游戏.在游戏中,他发现,这个游戏的伤害计算有一个规律,规律如下 1. 拥有一个伤害串为长度为\(n\)的\(01\)串. 2 ...