Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically aligning text next to a radio button

This is a basic CSS question, I have a radio button with a small text label after it. I want the text to appear centered vertically but the text is always aligned with the button of the radio button in my case.

<p><input type="radio" id="opt1" name="opt1" value="1" />A label</p>

Here is a Jsfiddle:

http://jsfiddle.net/UnA6j/

Any suggestions?

Thanks,

Alan.

like image 223
Alan A Avatar asked Jul 25 '13 11:07

Alan A


People also ask

How do you vertically align labels?

How to center text vertically in a regular label control. The CSS tag vertical-align does not work but there is a work-around of sorts...for some reason padding-top seems to work. So you can set a value for the padding-top and then adjust the height of your label to get the text where you want it to be.

What aligns the text in center vertically?

To center both vertically and horizontally, use padding and text-align: center : I am vertically and horizontally centered.


9 Answers

Use it inside a label. Use vertical-align to set it to various values -- bottom, baseline, middle etc.

http://jsfiddle.net/UnA6j/5/

like image 181
Prasanth Avatar answered Sep 25 '22 01:09

Prasanth


I think this is what you might be asking for

http://jsbin.com/ixowuw/2/

CSS

label{
  font-size:18px;
  vertical-align: middle;
}

input[type="radio"]{
  vertical-align: middle;
}

HTML

<span>
  <input type="radio" id="oddsPref" name="oddsPref" value="decimal" />
  <label>Decimal</label>
</span>
like image 22
Rahul Thakur Avatar answered Sep 26 '22 01:09

Rahul Thakur


Used to this

    input[type="radio"]{
    vertical-align:top;
    }
p{
    font-size:10px;line-height: 18px;
}

Demo

like image 27
Rohit Azad Malik Avatar answered Sep 26 '22 01:09

Rohit Azad Malik


This will give dead on alignment

input[type="radio"] {
  margin-top: 1px;
  vertical-align: top;
}
like image 32
Nils Avatar answered Sep 25 '22 01:09

Nils


simple and short solution add below style:

style="vertical-align: text-bottom;"
like image 33
Vasant Avatar answered Sep 22 '22 01:09

Vasant


HTML:

<label><input type="radio" id="opt1" name="opt1" value="1"> A label</label>

CSS:

label input[type="radio"] { vertical-align: text-bottom; }
like image 41
Edward Brey Avatar answered Sep 26 '22 01:09

Edward Brey


You may try something like;

<p><input type="radio" id="oddsPref" name="oddsPref" value="decimal" /><span>Decimal</span></p>

and give the span a margin top like;

span{
    margin-top: 4px;
    position:absolute;
}

here is the fiddle http://jsfiddle.net/UnA6j/11/

like image 38
Alfred Avatar answered Sep 24 '22 01:09

Alfred


You need to align the text to the left of radio button using float:left

input[type="radio"]{
float:left;
}

You may use label too for more responsive output.

like image 31
Sunil Kumar Avatar answered Sep 22 '22 01:09

Sunil Kumar


You could also try something like this:

input[type="radio"] {
  margin-top: -1px;
  vertical-align: middle;
}
  <label  class="child"><input id = "warm" type="radio" name="weathertype" value="warm" checked> Warm<br></label>
<label class="child1"><input id = "cold" type="radio" name="weathertype" value="cold" checked> Cold<br></label>
like image 42
Olivia Steger Avatar answered Sep 26 '22 01:09

Olivia Steger