简体   繁体   中英

Bootstrap Grid Alignment Issues

So I'm following a tutorial for RoR but I can't seem to get the alignment right.If I copy and paste the code for the tutorial, it will look like this

Here is the code:

<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user) do |f| %>

  <%= f.label :name %>
  <%= f.text_field :name %>

  <%= f.label :email %>
  <%= f.email_field :email %>

  <%= f.label :password %>
  <%= f.password_field :password %>

  <%= f.label :password_confirmation, "Confirmation" %>
  <%= f.password_field :password_confirmation %>

  <%= f.submit "Create my account", class: "btn btn-primary" %>
<% end %>

But if I put col-md-1, then it sort of works, looking like this

Is it possible to still use col-md-6 but have it properly aligned like the second photo? I don't know what else to change other than the numbers.

I am not able to test this right now but you may be able to change your first line of your form to:

 <%= form_for @user, :html => {:class => "form-horizontal"} do |f| %>

This should add the html and css need to make the form horizontal:

 <form class="form-horizontal">

Some what like this example: https://jsfiddle.net/obp9x1yr/7/

This might be a good post to read for more information: Rails Bootstrap how to format form_for (width grid collapses)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM