Note that there are some explanatory texts on larger screens.

plurals
  1. POAppend/prepend bootstrap icons with simple_form
    primarykey
    data
    text
    <p>Twitter Bootstrap icons are pretty deadly <a href="http://twitter.github.com/bootstrap/base-css.html#icons" rel="noreferrer">seen here</a>. </p> <p>Look at the bottom right hand corner of that section. See that email with an icon prepended? That is what I want to do. I want to make simple_form and boostrap play nicely.</p> <p>Here's what I've found that will prepend the icon to the input:</p> <pre><code>= f.input :email, :wrapper =&gt; :append do = f.input_field :email &lt;span class="add-on"&gt;&lt;i class="icon-envelope"&gt;&lt;/i&gt;&lt;/span&gt; </code></pre> <p>But it isn't flush (that could be fixed by changing offsets in CSS) and it's pretty ugly. For reference, here is the CSS fix (add it to your bootstrap_overrides.css.less file):</p> <pre><code>.input-prepend .add-on, .input-append input { float: left; } </code></pre> <p>Does someone know a less hacky way to make simple_form prepend or append an icon with bootstrap?</p> <h3>Update:</h3> <p>The answer below made me have another look at it. HAML usually adds whitespace everywhere, but there is a <a href="http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#whitespace_removal__and_" rel="noreferrer">workaround</a></p> <p>Here is an update for the original HAML which removes the whitespaces and doesn't require the CSS hack:</p> <pre><code>= f.input :email, :wrapper =&gt; :append do = f.input_field :email %span.add-on&gt; %i.icon-envelope </code></pre> <p>That little greater than (>) makes all the difference. The output HTML has no newlines between the input and the span.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload