需要使用色 #ec6337(當然可以是任意顏色),解決問題:記住密碼定制 CheckBox,解釋全在注釋里
主要使用到 ::before 或 ::after 偽類處理,偽裝成內部的那個勾
- html
-
<label>
-
<input type="checkbox" /> // 注意嵌在 label 里面
-
記住密碼
-
<div class="show-box" /> // 注意嵌在 label 里面
-
</label>
- CSS(LESS)
-
label {
-
position: relative;
-
cursor: pointer;
-
-
input {
-
cursor: pointer;
-
}
-
-
input:checked + .show-box {
-
background: #ec6337;
-
}
-
-
.show-box {
-
position: absolute;
-
top: 0;
-
left: 0;
-
width: 16px;
-
height: 16px;
-
border-radius: 2px;
-
border: 1px solid #d8d8d8;
-
background: white; // 這里取個巧,與下面顏色一樣而已
-
-
&:before { // 使用了 absolute 所以無所謂是 before 還是 after
-
content: ''; // 空白內容占位,當做盒模型處理,見下面
-
position: absolute;
-
top: 2px;
-
left: 6px;
-
width: 3px; // 勾的短邊
-
height: 8px; // 勾的長邊
-
border: solid white; // 勾的顏色
-
border-width: 0 2px 2px 0; // 勾的寬度
-
transform: rotate(45deg); // 定制寬高加上旋轉可以偽裝內部的白色勾
-
}
-
}