【发布时间】:2017-01-05 00:25:52
【问题描述】:
我有自定义单选按钮,我尝试在一行中显示多个单选按钮。目前,我的代码工作正常,但我的问题是我正在为标签添加固定宽度,在我的情况下是 width:50px;。
如果我的文字较长...我的文字与下一个单选按钮重叠。有没有办法避免固定宽度?像 calc() 这样的函数似乎对我的情况没有帮助。
我也试过只使用min-width 而不是width。
* {
box-sizing: border-box;
}
input[type="radio"] {
display: none;
cursor: pointer;
}
label {
cursor: pointer;
display: inline-block;
width: 50px;
position: relative;
}
.radio span.custom > span {
margin-left: 22px;
}
.radio .custom {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 3px;
display: inline-block;
height: 20px;
left: 0;
position: absolute;
top: 0;
width: 20px;
}
.radio input:checked + .custom:after {
background-color: #0574ac;
border-radius: 100%;
border: 3px solid #fff;
content: "";
display: block;
height: 12px;
position: absolute;
top: 0;
width: 12px;
}
.radio input + .custom {
border-radius: 100%;
}
.checkbox input:checked .custom {
background-color: blue;
border-color: blue;
}
<label class="radio">
<input type="radio">
<span class="custom"><span>One</span></span>
</label>
更新:
我需要将文本放在<span class="custom"> 标记内。我不必在那里有内部跨度标签
【问题讨论】: