Jeff Zivkovic
Jeff Zivkovic

Reputation: 587

Radio Buttons Won't Align Left or Inline

I'm working on a rails form, and the radio buttons stubbornly remain center-aligned no matter how I try to arrange their CSS and classes. More importantly, I cannot get them to display inline with the button label. They display one line above the label. The label is aligned left.

The form:

<%= form_tag students_path, :method => 'get' do %>
  <%= text_field_tag :search, params[:search] %>

  <%= radio_button_tag(:whichParam, "studentNum", :checked => true)  %>
  <%= label_tag(:studentNum, "Student Number") %>  
  <%= radio_button_tag(:whichParam, "last_name") %>
  <%= label_tag(:last_name, "Last Name") %>

  <%= submit_tag "Search", :name => nil %>

<% end %>

For the CSS, I've tried

.radio {
    display: inline;
}

.label {
   display: inline;
}

I've also tried erasing all CSS that refers to radio buttons or labels.

My guess is that I must have another line somewhere in my CSS that is causing the buttons to display center. But I can't find any other sections that might be affecting this.

Thank you in advance for any insight.

Upvotes: 0

Views: 304

Answers (1)

Ryan Murphy
Ryan Murphy

Reputation: 842

To get the label to display inline with the button you need to use the radio-inline class like this:

<%= radio_button_tag(:whichParam, "last_name", class: 'radio-inline') %>
<%= label_tag(:studentNum, "Student Number") %> 

Upvotes: 1

Related Questions