2 回答
TA贡献1877条经验 获得超6个赞
也不是最佳解决方案,也不是最佳实践,但这是我带来的:
我的 JSX
const CheckBox2: FC<ICheckBox2Props> = ({ label, type = "checkbox", className, labelClassName, ...props }) => {
return (
<label className={[styles.container, className ?? ""].join(" ")}>
<input
{...props}
type={type}
/>
<div className={styles.inputContainer}>
</div>
{label && <span className={[styles.label, labelClassName ?? ""].join(" ")} >{label}</span>}
</label>
);
};
CSS
.container {
display: inline-flex;
align-items: center;
margin-right: 48px;
position: relative;
.inputContainer{
position: absolute;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
height: 16px;
width: 16px;
box-sizing: border-box;
border: 1px solid #ABACAD;
border-radius: 2px;
}
>input{
opacity: 0;
height: 16px;
width: 16px;
&:checked + .inputContainer {
height: 16px;
width: 16px;
box-sizing: border-box;
border: 1px solid #2D3641;
border-radius: 2px;
background-color: #2D3641;
background-image: url(../../../../assets/images/icons/ico_check.png);
background-size: 10px 9px;
background-repeat: no-repeat;
background-position: center;
}
}
}
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
.container{
.inputContainer{
top: 2px;
left: 0px
}
}
}
添加回答
举报