Prepended input label (simple_form + bootstrap-sass) off by a few pixels

二次信任 提交于 2019-12-05 18:16:04

I don't really know what the problem is here, but I had the same thing.

Comparing the span.add-on tag I found that they had a float: left on theirs. I added that and it seemed to do the trick.

I also noticed they are using twitter 2.01. I'm using 2.02, so something might have changed.

EDIT: That messed up the append span.

.input-prepend .add-on,
.input-append input {
  float: left;
}

Is what I added. It doesn't feel right, but it's working for now. Hopefully someone else more knowledgeable of bootstrap can help out.

I have not looked at the changes to see why, but I can confirm that it works as expected in 2.0.1 and has the described gap in 2.0.2. To revert to the old, correct behavior you can replace the existing bootstrap-sass line in your Gemfile with:

gem 'bootstrap-sass', '2.0.1'

and update your bundle.

You need to add this: content_tag :span, "attribute", :class => "add-on", :style => 'margin-right: -5px;'

The accepted solution will cause problems if there is an error on the page due to validations. Simple_form actually has a wrapper that will allow you to do this and is much better when handling errors.

<%= f.input :name, :wrapper => :append, :class => "inline" do %>
    <%= f.input_field :name%>
    <%= content_tag :span, "@", :class => "add-on abbn" %>
<% end %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!