我正在绑定我的复选框右侧的文本。目前文本出现在多行中。对齐自定义复选框问题css
我试图改变宽度,并赋予它一个固定的宽度:
.checkbox span.custom {
margin-left: 34px;
display: inline-block;
width: 100px; // MY TRY
}
,但它正在改变复选框的大小不是文本旁边。
CSS:
* {
box-sizing: border-box;
}
label {
display: inline-block;
}
.checkbox {
position: relative;
min-height: 24px;
font-size: 1.6rem;
}
.checkbox input {
-webkit-tap-highlight-color: transparent;
height: 10px;
margin: 6px;
opacity: 0;
outline: none;
position: absolute;
left: 1px;
top: 1px;
width: 10px;
}
.checkbox .custom {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 3px;
display: inline-block;
height: 24px;
left: 0;
position: absolute;
top: 0;
width: 24px;
}
.checkbox span {
display: inline-block;
margin-left: 34px;
margin-top: 0;
position: relative;
top: 3px;
}
.checkbox input:checked:not(:disabled) + .custom {
background-color: #0574ac;
border-color: #0574ac;
}
.checkbox span {
margin-left: 0px;
}
.checkbox span.custom {
margin-left: 34px;
display: inline-block;
width: 100px; // MY TRY
}
.checkbox span.custom .radio span.custom {
margin-left: 34px;
margin-right: 34px;
display: flex;
}
.radio input:checked + .custom:after {
background-color: #0574ac;
border-radius: 100%;
border: 3px solid #fff;
content: "";
display: block;
height: 16px;
position: absolute;
width: 16px;
}
HTML:
<label for="checkbox1" class="checkbox">
<input id="checkbox1" type="checkbox" role="checkbox" /><span class="custom">Checkbox 1</span>
</label>
嗯为什么一些很多的CSS?你只想让标签与复选框对齐? –
是的,我需要将标签与复选框对齐。左边的标签和右边的复选框@AdamBuchananSmith – user4756836
@ user4756836,我刚才注意到这里的评论,你想在标签文本和复选框之间切换。我也为此添加了一个例子,欢迎您在答案中检查更新。 – Dekel