0

I need my input radio elements + associated text to be the same width for alignment purposes. I tried this:

.rad {      
    width: 80px;
}

...but that only works on the radio element itself (centers them in a sea of blankness).

So I tried this:

.rad text {      
    width: 160px;
}

...but it does nothing.

The html intended for styling is:

<input type="radio" class="rad" id="visitor" name="travelertype" />Visitor
<input type="radio" class="rad" id="ucstudent" name="travelertype"/>UC Student
<input type="radio" class="rad" id="ucemployee" name="travelertype"/>UC Employee

UPDATE 2

Trying the answer, I get:

enter image description here

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

3 Answers3

1

You should put the text after each radio button in a <label> for screen readers. This will also help with the CSS.

<td><input type="radio" class="rad" id="visitor" name="travelertype" /><label for="Visitor">Visitor</label></td>
<td><input type="radio" class="rad" id="ucstudent" name="travelertype"/><label for="UC Student">UC Student</label></td>
<td><input type="radio" class="rad" id="ucemployee" name="travelertype"/><label for="UC Employee">UC Employee</label></td>

You can style the whole cell with the container <td>.

td {
    width: 80px;
}
DivideByZero
  • 535
  • 4
  • 14
1

See this https://jsfiddle.net/byB9d/6228/

<p><input type="radio" class="rad" id="visitor" name="travelertype" /> Value</p>

<p><input type="radio" class="rad" id="ucstudent" name="travelertype"/>
    UC Student</p>

<p><input type="radio" class="rad" id="ucemployee" name="travelertype"/>
    UC Employee</p>
Adam Buchanan Smith
  • 9,422
  • 5
  • 19
  • 39
1

You'll need to change the markup to achieve this. There are many ways, here's 2 of them.

Method 1: Use separate table columns for radio buttons and the selects.

<table>
   <tr>
      <td>
        <input type="radio" class="rad" id="visitor" name="travelertype" />Visitor
      </td>
      <td>
         <select ...>
      </td>
   </tr>

   ... and so on.
</table>

Method 2: Wrap the text in <label>s and add style to the labels

<input type="radio" class="rad" id="visitor" name="travelertype" /><label for="travelertype" class="label-radio">Visitor</label>

CSS:

label.label-radio {
    width: 100px;
}
John Bupit
  • 10,406
  • 8
  • 39
  • 75