
盒子里的元素发生像素偏移
你的自定义 input checkbox 选择框样式在不同的分辨率下表现不一致,在选中时红色的小元素相对于外框无法居中。
这个问题的根源在于像素单位的使用。在不同分辨率下,像素点的尺寸可能存在差异,导致相对位置出现偏差。
为了解决这个问题,建议将 px 单位转换为相对单位,例如 rem 或 em。这些单位基于浏览器字体的尺寸,因此在不同的分辨率下保持一致。
以下是对你提供的代码的修改:
.clause-content {
display: flex;
flex-direction: row;
align-items: start;
}
.clause-input {
display: inline-block;
vertical-align: middle;
width: 1rem;
height: 1rem;
cursor: pointer;
position: relative;
background-color: #fff;
margin-right: 0.8rem;
border: 0.1rem solid rgba(237, 30, 14, 0.15);
}
.clause-input input {
opacity: 0;
}
.clause-input input:checked + i {
width: 0.6rem;
height: 0.6rem;
position: absolute;
left: 50%;
top: 50%;
margin-left: -0.3rem;
margin-top: -0.3rem;
background-color: #ed1c24;
}
登录后复制
以上就是自定义 input checkbox 样式在不同分辨率下表现不一致,如何解决?的详细内容,更多请关注米云其它相关文章!
