我正在尝试将一个表单包装在一个 div 中,而 div 内部似乎唯一的东西是电子邮件和密码表单字段。密码确认就像它不在 div 内部一样。
这是 View 。我在正确的目录中有一个名为 _sign_up_form.html.erb 的部分。
<div id="sign_up_form">
<%= render 'sign_up_form'%>
</div><!--end of the sign_up_form-->
这是部分内容
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email, :size => 40 %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, :size => 40 %>
</div>
</div>
<div class="field">
<%= f.label :confirmation %><br />
<%= f.password_field :password_confirmation, :size => 40 %>
</div>
<div class="actions">
<%= f.submit 'Sign up', :controller => 'users' , :action => 'post'%>
</div>
<% end %>
我试图通过这样做来改变表单的位置:
#sign_up_form{
position:relative;
left:400px;
background-color:green;
}
表单中唯一变绿并移动的部分是电子邮件和密码字段。密码确认和提交按钮留在同一个地方,背景没有变绿。为什么会这样?
最佳答案
你有一个额外的 </div>
在密码和密码确认字段之间 - 这将关闭 sign_up_form
分区
关于ruby-on-rails - 为什么密码确认不会留在 div 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6672674/