Search code examples
csshtmlvertical-alignment

How to align input="radio" with their labels?


I know there are a lot answers here. I searched, tried to adapt but I failed all the time, that is why I am asking now.

I have the following problem. I want, both, labels and there inputs to be in the same line: Yes o No o (o symbolize the input).

Here my following code, remark that I changed the display property of label to inline block:

<div class="col-sm-3">
        <label>Yes</label>
        <input type="radio" name="yes/no" checked>
        <label>No</label>
        <input type="radio" name="yes/no" >
    </div> 

Sorry for answering, although there are a lot of similar questions and answers but adapting them did just not work...


Solution

  • If you want the inputs and the label to be 'bottom-aligned', try using vertical-align: text-bottom.

    input[type='radio'] {
      vertical-align: text-bottom;
      margin-bottom: 1px;
    }
    div {
      display: inline-block;
      border: 1px solid black;
    }
    <div class="col-sm-3">
        <label>Yes</label>
        <input type="radio" name="yes/no" checked>
        <label>No</label>
        <input type="radio" name="yes/no" >
    </div>