简体   繁体   English

前置输入 label (simple_form + bootstrap-sass) 关闭几个像素

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

I want to use the text input field seen here:我想使用此处显示的文本输入字段:

http://simple-form-bootstrap.plataformatec.com.br/articles/new http://simple-form-bootstrap.plataformatec.com.br/articles/new

(It's the second text input field on that page.) (这是该页面上的第二个文本输入字段。)

I have it working in other Rails apps but for some reason in my current one there is a several-pixel gap between the prepended label and the text input.我让它在其他 Rails 应用程序中工作,但出于某种原因,在我当前的应用程序中,前置的 label 和文本输入之间存在几个像素的差距。 I've installed simple_form with the --bootstrap option, and have verified that the Rails/haml/bootstrap/bootstrap-sass versions are the same as the working rails app.我已经使用--bootstrap选项安装了 simple_form,并验证了 Rails/haml/bootstrap/bootstrap-sass 版本与工作中的 Rails 应用程序相同。

I don't override any of the related css in my stylesheets (I commented it all out to be sure).我没有在我的样式表中覆盖任何相关的 css(我将其全部注释掉以确保)。

Any ideas why Bootstrap isn't behaving as it should?知道为什么 Bootstrap 的行为不正常吗?

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.比较span.add-on标签,我发现他们有一个float: left在他们的标签上。 I added that and it seemed to do the trick.我添加了它,它似乎可以解决问题。

I also noticed they are using twitter 2.01.我还注意到他们正在使用 twitter 2.01。 I'm using 2.02, so something might have changed.我使用的是 2.02,所以有些东西可能已经改变了。

EDIT: That messed up the append span.编辑:这搞砸了 append 跨度。

.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.希望其他更了解 bootstrap 的人可以提供帮助。

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.我没有查看更改以了解原因,但我可以确认它在 2.0.1 中按预期工作并且在 2.0.2 中有描述的差距。 To revert to the old, correct behavior you can replace the existing bootstrap-sass line in your Gemfile with:要恢复到旧的正确行为,您可以将 Gemfile 中现有的 bootstrap-sass 行替换为:

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;'您需要添加: 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. Simple_form 实际上有一个包装器可以让你这样做,并且在处理错误时会好得多。

<%= f.input :name, :wrapper => :append, :class => "inline" do %>
    <%= f.input_field :name%>
    <%= content_tag :span, "@", :class => "add-on abbn" %>
<% end %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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