Positioning Radio Buttons and Labels on the Same Line
In HTML forms, aligning radio buttons and their associated labels on a single line can be challenging. To achieve this, several CSS techniques can be employed.
The suggested HTML structure positions the label and input elements:
<label for="one">First Item</label>
<input type="radio" id="one" name="first_item" value="1" />
To align them horizontally, add the following CSS rules:
label {
float: left;
clear: none;
display: block;
padding: 0px 1em 0px 8px;
}
input[type=radio],
input.radio {
float: left;
clear: none;
margin: 2px 0 0 2px;
}
This positions the label and radio button next to each other. To ensure that multiple radio buttons are aligned on the same line, use the following markup:
<fieldset>
<div class="some-class">
<input type="radio" class="radio" name="x" value="y" id="y" />
<label for="y">Thing 1</label>
<input type="radio" class="radio" name="x" value="z" id="z" />
<label for="z">Thing 2</label>
</div>
</fieldset>
With the appropriate CSS rules, the radio buttons and labels will be aligned on the same line.
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3