如何实现这种复选框(如下图所示)?我试过一些代码,但它不会像我预期的那样工作。我不熟悉css之前,之后伪元素。
JSFiddle
.chkbox {
height: 15px;
width: 15px;
background-color: #fff;
border: 1px solid #ddd;
position: relative;
transition: border-color ease 0.125s;
-ms-transition: border-color ease 0.125s;
-moz-transition: border-color ease 0.125s;
-webkit-transition: border-color ease 0.125s;
cursor: pointer;
border-radius: 2px;
}
.chkbox:before {
right: -1px;
width: 1px;
top: -1px;
height: 8px
}
.chkbox:after {
top: -1px;
right: 0;
width: 2px;
height: 2px
}
最佳答案
为什么不使用剪辑路径?删除伪元素并添加类似clip-path: polygon(0 0, 65% 0%, 65% 25%, 100% 25%, 100% 100%, 0 100%);
.chkbox {
height: 15px;
width: 15px;
background-color: #fff;
border: 1px solid #ddd;
position: relative;
transition: border-color ease 0.125s;
-ms-transition: border-color ease 0.125s;
-moz-transition: border-color ease 0.125s;
-webkit-transition: border-color ease 0.125s;
cursor: pointer;
border-radius: 2px;
clip-path: polygon(0 0, 65% 0%, 65% 25%, 100% 25%, 100% 100%, 0 100%);
}
<div class="chkbox"></div>
这很方便,顺便说一下http://bennettfeely.com/clippy/
关于html - CSS剪切了右上半边和右上半边,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42689380/