0

I'm trying to center all my radio buttons vertically with its label, but vertical-align doesn't help:

input[type="radio"]{
    vertical-align: center;
}
<p style="display:inline-block;margin:0 0;"> Option: </p>
<label>
<input type="radio" name="group1"> Label1
</label>
<label>
<input type="radio" name="group1"> Label2
</label>
<label>
<input type="radio" name="group1"> Label3
</label>
Cœur
  • 32,421
  • 21
  • 173
  • 232
user924
  • 3,322
  • 2
  • 26
  • 60

3 Answers3

0

Correct is: vertical-align: middle;

Tony Duffill
  • 219
  • 1
  • 5
0

You can use these CSS settings:

input[type="radio"] {
  display: block;
  margin: 0 auto 5px auto;
  
}
label {
  text-align: center;
  display: inline-block;
  width: 80px;
}
<p style="display:inline-block;margin:0 0;"> Option: </p>
<label>
<input type="radio" name="group1"> Label1
</label>
<label>
<input type="radio" name="group1"> Label2
</label>
<label>
<input type="radio" name="group1"> Label3
</label>

And applied to your jsfiddle: https://jsfiddle.net/p5ts1rco/1/

Johannes
  • 53,485
  • 15
  • 52
  • 104
  • radio buttons above text?) Anyway I solved it: https://stackoverflow.com/a/45652690/7767664 – user924 Aug 12 '17 at 16:48
  • "center vertically with its label" - I understood you that way... What is centered in your solution, and what's the difference to the question? – Johannes Aug 12 '17 at 16:50
0

[Solved]

I edit this example for checkboxes https://stackoverflow.com/a/494922/7767664 (changed to radio buttons):

.checkboxes label {
  display: block;
  float: left;
  padding-right: 3px;
  white-space: nowrap;
}
.checkboxes input {
  vertical-align: middle;
}
.checkboxes label span {
  vertical-align: middle;
  font-size:29px;
}
<div class="checkboxes">
    <label> <span>Option: </span></label>
    <label><input type="radio" name="group1" id="x" /> <span>Label text x</span></label>
    <label><input type="radio" name="group1" id="y" /> <span>Label text y</span></label>
    <label><input type="radio" name="group1" id="z" /> <span>Label text z</span></label>
</div>
user924
  • 3,322
  • 2
  • 26
  • 60