https://codesandbox.io/s/frosty-haze-r4v9r
我正在使用伪类将默认的单选输入替换为自定义的单选输入,并试图准确了解其工作原理。
为什么检查时我的:before元素上的高度和宽度1px不能显示,但是2px的值可以正确显示?
HTML和CSS渲染
.css-19erv9f {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
}
.css-19erv9f:before {
content: "";
position: absolute;
z-index: 1;
top: 0;
left: 0;
width: 1px;
height: 1px;
background: blue;
-webkit-transform: scale(0, 0);
-ms-transform: scale(0, 0);
transform: scale(0, 0);
}
.css-19erv9f:checked:before {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.css-19erv9f:focus {
outline: none;
}
.css-19erv9f:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 15px;
height: 15px;
border: 1px solid pink;
}
<div id="root">
<div class="App"><input type="radio" class="css-19erv9f"></div>
</div>