【发布时间】:2017-01-06 03:15:05
【问题描述】:
我正在尝试将我的自定义单选按钮对齐成一行,但我遇到了问题。如果文本很长但单选按钮相互重叠。我不想为它们中的任何一个分配固定宽度。此外,如果我想更改单选按钮的边框以进行错误处理,我需要在那里设置.radio .custom 样式。我愿意更改 html 结构,但我需要将 Text 放在 custom span 内。如果需要,我可以去掉内跨。
我尝试过使用:
display:flex;
在label
但它最终给了我每个选项。
* {
box-sizing: border-box;
}
input[type="radio"] {
display: none;
cursor: pointer;
}
label {
cursor: pointer;
min-width: 50px;
display: inline-block;
position: relative;
}
.radio span.custom > span {
margin-left: 24px;
margin-right: 10px;
}
.radio .custom {
content: '';
height: 20px;
left: 0;
top: 0;
width: 20px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 100%;
position: absolute;
}
.radio input:checked + .custom:before {
background-color: blue;
border-radius: 100%;
border: 3px solid #fff;
content: "";
display: block;
height: 12px;
position: absolute;
top: 0;
width: 12px;
z-index: 1;
left: 0;
}
.radio input + .custom:after {
border-radius: 100%;
}
.checkbox input:checked .custom {
background-color: blue;
border-color: blue;
}
<label class="radio">
<input type="radio">
<span class="custom"><span>Onasasasase</span></span>
</label>
<label class="radio">
<input type="radio">
<span class="custom"><span>Two</span></span>
</label>
【问题讨论】: