【发布时间】:2014-08-16 13:36:07
【问题描述】:
引导文档和 SO 答案似乎并没有为我回答这个问题。我想在它的标签旁边放一个复选框。这很简单。我一定是做错了什么,但我想不通。
我正在使用:
#gemfile.lock, in my Rails application.
bootstrap-sass (3.1.1.1)
rails (4.0.3)
在我的 Rails 视图中:
# devise/registrations/new.html.erb
<%= f.label :accept_terms, class: "checkbox" do %>
<%= f.check_box :accept_terms %> I agree to the terms and conditions listed here
<% end %>
生成以下 HTML:
<label class="checkbox" for="user_accept_terms">
<input name="user[accept_terms]" type="hidden" value="0"><input id="user_accept_terms" name="user[accept_terms]" type="checkbox" value="1"> I agree to the terms and conditions listed here
</label>
或者,在视图中:
# devise/registrations/new.html.erb
<%= f.label :accept_terms, "I agree to the terms and conditions listed here", class: "checkbox" %>
<%= f.check_box :accept_terms %>
生成 HTML:
<label class="checkbox" for="user_accept_terms">I agree to the terms and conditions listed here</label>
<input name="user[accept_terms]" type="hidden" value="0"><input id="user_accept_terms" name="user[accept_terms]" type="checkbox" value="1">
这两种尝试都会导致复选框和标签出现在不同的行上。
我什至尝试过手动覆盖块显示属性(成功,根据 Chome 的检查):
#user_accept_terms { display: inline;}
label.checkbox { display: inline; }
我怎样才能让这些元素表现出来?
提前谢谢你。
【问题讨论】:
标签: css ruby-on-rails forms twitter-bootstrap