Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align radio buttons horizontally below labels

So I am using the following HTML to display 4 radio buttons horizontally centered underneath their respective labels in a jsp:

<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>

And CSS:

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

But I keep getting misaligned buttons like the following

It wont go horizontal:/

What might I be missing here?

like image 362
Sean Avatar asked Sep 27 '22 11:09

Sean


1 Answers

As I understand it you want this

#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>

Note:

This is incorrect on two fronts:

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

Firstly, the element has an ID of radioGroup not class

Secondly, the input is not a child of the label but rather a sibling

like image 115
Paulie_D Avatar answered Oct 22 '22 10:10

Paulie_D