【发布时间】:2016-10-15 22:36:44
【问题描述】:
我有一个自定义复选框,其中填充了边框、颜色等的转换以及 3d 转换以将其翻转。如果未选中复选框,它看起来很好并且在状态之间转换得很好,但是,如果复选框在 dom 加载时被赋予选中属性,那么它必须旋转到位并且复选框在背面可见。
注意:虽然我链接了 JsFiddle,以便您可以看到代码,但问题并没有发生在小提琴中。仅当样式通过样式表链接时才会发生。
https://jsfiddle.net/tj2djeej/
/* Radio & Checkbox */
input.flipCheckbox {
-webkit-transition: transform .5s linear 0s;
-webkit-transform-style: preserve-3d;
-webkit-appearance: none;
-webkit-transform: rotatey(0deg);
-webkit-perspective: 800;
-webkit-transform-style: preserve-3d;
box-sizing: border-box;
position: relative;
outline: none;
width: 26px;
height: 26px;
border: 3px solid #C15649;
cursor: pointer;
}
input.flipCheckbox:checked {
-webkit-transform: rotatey(180deg);
}
input.flipCheckbox:after {
-webkit-transform: rotatey(-180deg);
-webkit-transition: color 0s linear .25s, -webkit-text-stroke-color 0s linear .25s;
-webkit-text-stroke-color: transparent;
cursor: pointer;
line-height: 26px;
font-size: 14px;
width: 26px;
height: 26px;
position: absolute;
z-index: 1;
top: -3px;
left: -3px;
color: transparent;
text-align: center;
-webkit-text-stroke-width: 2px;
-webkit-text-stroke-color: transparent;
}
input.flipCheckbox:checked:after {
color: #C15649;
-webkit-text-stroke-color: #C15649;
}
input.flipCheckbox:after {
content: "\2713";
}
<input type="checkbox" class="flipCheckbox" />
<input type="checkbox" checked class="flipCheckbox" />
【问题讨论】:
-
:after和:before伪选择器在大多数浏览器中的输入元素中不起作用...改用复选框样式的附加标签。 -
@seahorsepip 哦哇不知道,谢谢你的提示。
-
我最终使用了一个完全不同的解决方案(包括添加一个 :before 元素),但事实证明这个答案对于简化我的代码以使其成为可能非常宝贵,所以我接受了它。谢谢!
标签: css css-transitions