Adding font-awesome icon inside a input field when using simple-form

JCC

I looked and used the solution for placing the font-awesome icons inside an input field box as outlined here.

StackOverflow answer

HTML

<input name="txtName" id="txtName">
<span class="fa fa-user errspan"></span>

CSS

.errspan {
   float: right;
   margin-right: 6px;
   margin-top: -60px;
   position: relative;
   z-index: 2;
   color: gray;
}

But it doesn't really work with simple-form as when you place the icon using css positioning, the icon would be in the wrong place when simple-form shows error messages below the fields themselves.

So for example, if you position the icon to work in one state where it looks great when the error message is displayed like this.

simple-form errors displayed

It ends up being incorrect in another state, like this. enter image description here

JCC

The solution turns out to be pretty simple and straight forward.

Move the icon html to be ahead of the input html like this.

HTML

<span class="fa fa-user errspan"></span>
<input name="txtName" id="txtName">

Then just adjust the CSS positioning so that it fits with this new convention.

CSS

.errspan {    
  float: right
  top: 24px
  right: 6px
  position: relative
  z-index: 2
  color: grey
}

You should be good to go. The icon will always stay exactly where you placed it no matter what the state the form is in.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Font Awesome icon inside text input element

From Dev

Changing Font Icon in WPF using Font Awesome

From Dev

Change color when hover a font awesome icon?

From Dev

Overlapping a font awesome icon inside a text field

From Dev

Include font awesome inside input type text

From Dev

Right border of div being cut off when using float:right with font awesome icon

From Dev

Change the font path when using Font Awesome

From Dev

change font-awesome icon when toggled

From Dev

Font awesome icon and text in input submit button?

From Dev

How to add Font Awesome icon into <input> button?

From Dev

How to insert font awesome icon into text input?

From Dev

Using Font Awesome as Select Icon

From Dev

Make Font Awesome icon a submit for a form

From Dev

Adding font awesome icon inline yet superscript with other element

From Dev

Font awesome icon font as a placeholder in input after adding class with jquery

From Dev

Font Awesome icon inside of HTML input with Angular working

From Dev

How do I add a Font Awesome icon to file input field

From Dev

Vertically centering Font Awesome icon inside nav

From Dev

using font awesome on input field button text

From Dev

Font awesome not loading when using Python simple http server

From Dev

Changing Font Icon in WPF using Font Awesome

From Dev

Change the font path when using Font Awesome

From Dev

change font-awesome icon when toggled

From Dev

Icon inside simple form

From Dev

Using Font Awesome as Select Icon

From Dev

When appending a font awesome icon in a button using jQuery the icon disappears when I click another button

From Dev

Vertically centering Font Awesome icon inside nav

From Dev

To create a grid using font awesome icon

From Dev

font-awesome icon not displaying inside the textarea

Related Related

  1. 1

    Font Awesome icon inside text input element

  2. 2

    Changing Font Icon in WPF using Font Awesome

  3. 3

    Change color when hover a font awesome icon?

  4. 4

    Overlapping a font awesome icon inside a text field

  5. 5

    Include font awesome inside input type text

  6. 6

    Right border of div being cut off when using float:right with font awesome icon

  7. 7

    Change the font path when using Font Awesome

  8. 8

    change font-awesome icon when toggled

  9. 9

    Font awesome icon and text in input submit button?

  10. 10

    How to add Font Awesome icon into <input> button?

  11. 11

    How to insert font awesome icon into text input?

  12. 12

    Using Font Awesome as Select Icon

  13. 13

    Make Font Awesome icon a submit for a form

  14. 14

    Adding font awesome icon inline yet superscript with other element

  15. 15

    Font awesome icon font as a placeholder in input after adding class with jquery

  16. 16

    Font Awesome icon inside of HTML input with Angular working

  17. 17

    How do I add a Font Awesome icon to file input field

  18. 18

    Vertically centering Font Awesome icon inside nav

  19. 19

    using font awesome on input field button text

  20. 20

    Font awesome not loading when using Python simple http server

  21. 21

    Changing Font Icon in WPF using Font Awesome

  22. 22

    Change the font path when using Font Awesome

  23. 23

    change font-awesome icon when toggled

  24. 24

    Icon inside simple form

  25. 25

    Using Font Awesome as Select Icon

  26. 26

    When appending a font awesome icon in a button using jQuery the icon disappears when I click another button

  27. 27

    Vertically centering Font Awesome icon inside nav

  28. 28

    To create a grid using font awesome icon

  29. 29

    font-awesome icon not displaying inside the textarea

HotTag

Archive