input自定义图标及其选中图标
如下图:想要不使用input标签的默认样式;此时需要准备两张正常、选中的图片。

代码如下:
//HTML结构
<div className="login-agreement">
<input className="login-agreement-input" type="checkbox" defaultChecked id="agreement" />
<label className="login-agreement-label" htmlFor="agreement">同意《用户服务协议》和《隐私政策》</label>
</div>
//CSS样式
input {
-webkit-appearance: none;
margin: 0;
width: .3733rem;
height: .3733rem;
padding: 0;
background: url('../../assest/2x/checkNormal.png') no-repeat center center;
background-size: .3733rem .3733rem;
outline: none;
}
input:checked {
background: url('../../assest/2x/checkSelect.png') no-repeat center center;
background-size: .3733rem .3733rem;
}

文章展示了如何使用HTML和CSS来实现输入框(input)的自定义样式,特别是如何为checkbox类型设置正常状态和选中状态的图标。通过修改input的样式,包括去除默认样式、设定背景图片及切换选中时的背景图片,可以实现不依赖默认样式的复选框效果。
3359

被折叠的 条评论
为什么被折叠?



