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

Sea*_*ean 5 html css alignment radio-button

因此,我使用以下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>
Run Code Online (Sandbox Code Playgroud)

和CSS:

.radioGroup label {
  display: inline-block;
  text-align: center;
  margin: 0 0.2em;
}
.radioGroup label input[type="radio"] {
  display: block;
  margin: 0.5em auto;
}
Run Code Online (Sandbox Code Playgroud)

但是我不断出现如下所示的未对齐按钮

它不会水平:/

我在这里可能会缺少什么?

Pau*_*e_D 5

据我了解你想要这个

#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;
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

笔记:

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

.radioGroup label input[type="radio"] {
  display: block;
  margin: 0.5em auto;
}
Run Code Online (Sandbox Code Playgroud)

首先,该元素的 ID 不是radioGroup

其次,输入不是标签的子级,而是同级