标签下方的中心单选按钮

2022-01-21 00:00:00 radio-button html css

假设我有一些单选按钮,其标签如下所示:

Let's say I have some radio buttons with their labels looking like this:

<label for="my_radio_button_id">My Label</label>
<input type="radio" name="radio" id="my_radio_button_id" />

如何将每个单选按钮置于其相应标签下方的中心并水平对齐?

How do I center each radio button below its corresponding label and align it horizontally?

推荐答案

FIDDLE

.checkboxgroup {
  display: inline-block;
  text-align: center;
}
.checkboxgroup label {
  display: block;
}

<div id="checkboxes">
  <div class="checkboxgroup">
    <label for="my_radio_button_id1">My Label1</label>
    <input type="radio" name="radio" id="my_radio_button_id1" />
  </div>
  <div class="checkboxgroup">
    <label for="my_radio_button_id2">My Label2</label>
    <input type="radio" name="radio" id="my_radio_button_id2" />
  </div>
  <div class="checkboxgroup">
    <label for="my_radio_button_id3">My Label3</label>
    <input type="radio" name="radio" id="my_radio_button_id3" />
  </div>
</div>

相关文章