Open WangShuXian6 opened 5 years ago
预览 https://codepen.io/WangShuXian6/pen/qyRVPQ
关联label标签与input标签
使label标签的for属性值与input 标签的id值相同 此时点击label将改变绑定的input的checked属性值 true或false 可将input 完全隐藏,label作为input的代理外观
switch.html
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href="./switch2.css"> </head> <body> <div class="switch"> <input type="checkbox" id="toggle"> <label for="toggle"><i></i></label> </div> </body> </html>
switch.less
@pink: #ff4777; @white: #fff;
.switch { position: relative; display: flex; width: 64px; height: 34px; border-radius: 34px; & > input { position: absolute; top: 0; left: 0; z-index: -10; opacity: 0; }
& > input:checked ~ label { background-color: @white; border: 1px solid rgba(255, 71, 119, 0.21); }
& > input:checked ~ label i { right: 30px; }
& > label { position: relative; display: flex; width: 64px; height: 34px; border-radius: 34px; background-color: @pink; transition: all 0.5s linear; border: 1px solid @pink; & > i { display: flex; position: absolute; top: 1px; right: 0; width: 32px; height: 32px; border-radius: 50%; background-color: @white; box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, 0.3); } } }
***
#### [:checked][2]
>:checked CSS 伪类选择器表示任何处于选中状态的radio(<input type="radio">), checkbox (<input type="checkbox">) 或("select") 元素中的option HTML元素("option")) 。用户通过点击元素或选择其他的值,可以改变该元素的 :checked 状态,并:checked属性赋给一个新的对象(例如其他的option值)。
[2]:https://developer.mozilla.org/zh-CN/docs/Web/CSS/:checked
>选择器示例
>input[type="radio"]:checked
>>表示页面上的所有选中的radio按钮
>input[type="checkbox"]:checked
>>表示页面上的所有选中的checkbox按钮
>option:checked
>>表示页面上的所有选中的select的选项
```css
/* any "checkable" element */
:checked {
width: 50px;
height: 50px;
}
/* only radio elements */
input[type="radio"]:checked {
margin-left: 25px;
}
/* only checkbox elements */
input[type="checkbox"]:checked {
display: none;
}
/* only option elements */
option:checked {
color: red;
}
使用隐藏的checkboxes来存储一些CSS布尔值
- :checked伪类用于隐藏checkboxes。以下示例说明了如何显示/隐藏一些可扩展的元素,只需一个单击按钮
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>Expandable elements</title> <style> #expand-btn { margin: 0 3px; display: inline-block; font: 12px / 13px "Lucida Grande", sans-serif; text-shadow: rgba(255, 255, 255, 0.4) 0 1px; padding: 3px 6px; border: 1px solid rgba(0, 0, 0, 0.6); background-color: #969696; cursor: default; border-radius: 3px; box-shadow: rgba(255, 255, 255, 0.4) 0 1px, inset 0 20px 20px -10px white; }
background: #B5B5B5;
box-shadow: inset rgba(0, 0, 0, 0.4) 0 -5px 12px, inset rgba(0, 0, 0, 1) 0 1px 3px, rgba(255, 255, 255, 0.4) 0 1px;
}
display: none;
}
display: table-row;
background: #cccccc;
}
display: block;
background: #cccccc;
}
Column #1 | Column #2 | Column #3 |
---|---|---|
[cell text] | [cell text] | [cell text] |
[cell text] | [cell text] | [cell text] |
[cell text] | [cell text] | [cell text] |
[cell text] | [cell text] | [cell text] |
[cell text] | [cell text] | [cell text] |
[some sample text]
[some sample text]
CSS3
CSS 模块状态
稳定模块(Stable modules)