我想我知道你在找什么,但如果我错过了标记,请纠正我.我假设您希望单选按钮位于其标签下方.如果您可以将<br>s 添加到标记中,这将更容易.
label {
float: left;
padding: 0 1em;
text-align: center;
}Run Code Online (Sandbox Code Playgroud)
<label for="myChoice1">Choice 1<br />
<input type="radio" id="myChoice1" name="myChoice" value="1" />
</label>
<label for="myChoice2">Choice ABC<br />
<input type="radio" id="myChoice2" name="myChoice" value="ABC" />
</label>
<label for="myChoice3">Choice qwerty<br />
<input type="radio" id="myChoice3" name="myChoice" value="qwerty" />
</label>
<label for="myChoice4">Choice--final<br />
<input type="radio" id="myChoice4" name="myChoice" value="final" />
</label>Run Code Online (Sandbox Code Playgroud)
...然后使用您自己的清算方法移动到下一行.
(在这里使用s 中的for属性<label>有点多余,但它不会伤害任何东西.)
而不是以下:
<label>Label <input type="radio" id="val" name="val" value="hello"></label>
Run Code Online (Sandbox Code Playgroud)
您可以使用它并分别设置两种样式:
<label for="val">Label</label>
<input type="radio" id="val" name="val" value="hello">
Run Code Online (Sandbox Code Playgroud)
小智 5
在不确切了解您想要什么布局的情况下,我无法更具体,但如果您只想获取单选按钮上方的标签,请在单选按钮上使用 display:block 。(显然,这是内联的,只是作为示例)
<label>Label <input style="display:block;" type="radio" id="val" name="val" value="hello" /></label>
Run Code Online (Sandbox Code Playgroud)