简体   繁体   中英

How do I center a form_for form on a page? Rails app

This is my form code:

<%= form_for @user do |f| %>
<%=f.label :username %>
<%=f.text_field :username %><br>
<%= f.label :email %>
<%= f.text_field :email %><br>
<%= f.label :password%>
<%= f.password_field :password %><br>
<%= f.submit %>
<%end%>

I managed to center everything but the form!

You need to center the form with styles. For example:

<div class='center-form'>
  <%= form_for(@user) do |f| %>
  ...
</div>

And then, in your stylesheets, add.center-form with required centerizing rules. Or you might do that without styles via Bootstrap. With "offset" rules (like offset-md-2) you might push div to center. But please refer to Bootstrap documentation to prototype and understand that.

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