【发布时间】:2020-11-27 14:23:37
【问题描述】:
我正在尝试实现类似于分段控件的单选按钮:
* {
margin: 0;
padding: 0;
}
.container {
background-color: brown;
width: 80vw;
}
.box {
display: flex;
flex-direction: row;
border: 2rem solid skyblue;
border-radius: 999px;
}
label {
flex: 1;
padding: 2rem;
border-radius: 999px;
text-align: center;
}
input {
display: none;
}
input:checked + label {
background-color: skyblue;
}
<div class="container">
<div class="box">
<input type="radio" id="hello" name="test" checked />
<label for="hello">Hello</label>
<input type="radio" id="world" name="test" />
<label for="world">World</label>
</div>
</div>
但是,嵌套标签和父 div 之间存在大约 1px 的恼人间隙:
这个问题类似于this question,但建议的解决方法对我的用例并不适用,因为我无法更改背景颜色。我也很好奇这是浏览器错误还是某种抗锯齿问题。
【问题讨论】: