gpt4 book ai didi

html - 如何在标签下方水平对齐单选按钮

转载 作者:太空狗 更新时间:2023-10-29 16:00:14 25 4
gpt4 key购买 nike

所以我使用以下 HTML 在 jsp 中的各自标签下方水平居中显示 4 个单选按钮:

<s:form action="markUser" name="markUser" method="post" namespace="/secure/admin">
<div id="radioGroup">

<label for="markStudent">Mark User as Student</label>
<input type="radio" name="mark" id="markStudent" value="Student" />

<label for="markAdmin">Mark User as Admin</label>
<input type="radio" name="mark" id="markAdmin" value="Admin" />

<label for="markService">Mark User as Service</label>
<input type="radio" name="mark" id="markService" value="Service" />

<label for="markNull">Mark User as Null</label>
<input type="radio" name="mark" id="markNull" value="Null" />

</div>
</s:form>

和 CSS:

.radioGroup label {
display: inline-block;
text-align: center;
margin: 0 0.2em;
}
.radioGroup label input[type="radio"] {
display: block;
margin: 0.5em auto;
}

但我一直收到如下所示的错位按钮

It wont go horizontal:/

我可能在这里遗漏了什么?

最佳答案

据我了解,你想要这个

#radioGroup .wrap {
display: inline-block;
}
#radioGroup label {
display: block;
text-align: center;
margin: 0 0.2em;
}
#radioGroup input[type="radio"] {
display: block;
margin: 0.5em auto;
}
<div id="radioGroup">
<div class="wrap">
<label for="markStudent">Mark User as Student</label>
<input type="radio" name="mark" id="markStudent" value="Student" />
</div>

<div class="wrap">
<label for="markAdmin">Mark User as Admin</label>
<input type="radio" name="mark" id="markAdmin" value="Admin" />
</div>
<div class="wrap">
<label for="markService">Mark User as Service</label>
<input type="radio" name="mark" id="markService" value="Service" />
</div>
<div class="wrap">
<label for="markNull">Mark User as Null</label>
<input type="radio" name="mark" id="markNull" value="Null" />
</div>
</div>

注意:

这在两个方面是不正确的:

.radioGroup label input[type="radio"] {
display: block;
margin: 0.5em auto;
}

首先,该元素的 ID 是 radioGroup 而不是类

其次,输入不是标签的,而是兄弟

关于html - 如何在标签下方水平对齐单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31145973/

25 4 0