Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Awesome icon placement when used in Bootstrap input with feedback #4313

Open
travislwatson opened this issue Sep 3, 2014 · 18 comments
Open

Comments

@travislwatson
Copy link

travislwatson commented Sep 3, 2014

Edit: Use the fix from @Azaret below, it works great!

When attempting to use Font-Awesome icons within a Bootstrap input with feedback, the placement is off:

image

Font-Awesome is overwriting a couple of rules that fix this alignment:

image

The workaround I'm currently using is to place the Font-Awesome <link> above Bootstrap to give the fa rules a lower precedence. Here's a snippet to reproduce (or in a codepen if you prefer):

<div class="form-group has-feedback">
    <label class="control-label">Font Awesome</label>
    <input type="text" class="form-control">
    <span class="fa fa-search form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
    <label class="control-label">Glyphicon</label>
    <input type="text" class="form-control">
    <span class="glyphicon glyphicon-search form-control-feedback"></span>
</div>
@tagliala
Copy link
Member

tagliala commented Sep 3, 2014

@traviswatsonws

Thanks for reporting this

Altough FA is declared as "designed for bootstrap", dave preferred to remove framework specific workarounds in FA 4.0.

You made the right choice. Otherwise, you should override some values but you should be careful because that will also affect input-lg and input-sm, which are not affected by this issue: http://codepen.io/anon/pen/nbuFH http://codepen.io/anon/pen/CvodD

A better approach would be change .form-control-feedback in bootstrap to .form-control + .form-control-feedback so it will take priority on .fa class.

I don't know where to document this, maybe a new section

@tagliala tagliala added this to the 5.0.0 milestone Sep 3, 2014
andrenarchy added a commit to paperhive/frontend that referenced this issue Feb 18, 2015
@nghuuphuoc
Copy link

Waiting for the fix.

@travislwatson
Copy link
Author

@nghuuphuoc The fix I mentioned (loading FontAwesome then Bootstrap, letting BS cascade over FA) worked well for me. The project shipped with this change, and I saw no issues related to it. I can't guarantee there aren't other side effects of that order, but I didn't see any.

@jdoles
Copy link

jdoles commented Mar 13, 2015

@traviswatsonws Thanks for the simple "fix". Saved me from venturing down a dark path.

@quantuminformation
Copy link

What is the best way to approach this one now? I'm using the latest fa and bootstrap.

@tagliala
Copy link
Member

@quantuminformation

fastest approach: #4313 (comment)

@quantuminformation
Copy link

@tagliala thanks thats great

@Azaret
Copy link

Azaret commented Aug 14, 2015

My favorite workaround without BS or FA override nor changing the link order is simply do this :

<div class="form-group has-feedback">
    <label class="control-label">Font Awesome</label>
    <input type="text" class="form-control">
    <span class="form-control-feedback">
        <i class="fa fa-search"></i>
    </span>
</div>

@tagliala
Copy link
Member

@Azaret thanks for sharing this!

@legshooter
Copy link

Thanks @Azaret! Great fix until the official one.

@tagliala
Copy link
Member

Just started this wiki, feel free to improve it: https://github.com/FortAwesome/Font-Awesome/wiki/Bootstrap-Caveats

@z3ntu
Copy link

z3ntu commented Feb 18, 2016

@Azaret Thank you very much!

@kezkankrayon
Copy link

@Azaret Thank you!

@mschoenbein
Copy link

@Azaret Thx!

@milanvdm
Copy link

Currently with Font Awesome and Bootstrap 4, I have the following problem using the posted solution:
image

@kezkankrayon
Copy link

kezkankrayon commented Feb 22, 2017

@milanvdm, Bootstrap 4 uses background images for validation feedback. For example, https://github.com/twbs/bootstrap/blob/v4-dev/scss/_variables.scss#L541 .

Bootstrap 3

https://jsfiddle.net/kezkankrayon/g9sx0ahr/

<div class="form-group has-feedback">
    <label class="control-label">Font Awesome</label>
    <div class="input-group">
      <span class="input-group-addon" id="basic-addon1"> <i class="fa fa-lock"></i></span>
      <input type="text" class="form-control" placeholder="Password" aria-describedby="basic-addon1">
    </div>
    <span class="form-control-feedback">
        <i class="fa fa-eye"></i>
    </span>
  </div>

Bootstrap 4

https://jsfiddle.net/kezkankrayon/mo5mhLtn/

 <div class="form-group has-feedback-custom">
    <label class="form-control-label" for="inputSuccess1">Bootstrap 4 input with custom feedback</label>
    <div class="input-group">
      <span class="input-group-addon" id="basic-addon1"> <i class="fa fa-lock"></i></span>
      <input type="text" class="form-control" placeholder="Password" aria-describedby="basic-addon1">
    </div>
    <span class="form-control-feedback-custom">
        <i class="fa fa-eye"></i>
    </span>
    <small class="form-text text-muted">Example help text that remains unchanged.</small>
  </div>
// SCSS derrived from Bootstrap 3 Form Control Feedback.

/* TODO: import Bootstrap4 variables */
$input-height-base: 38px; //TODO: use imported Bootstrap 4 variables.
$line-height-computed:20px; //TODO: use imported Bootstrap 4 variables.

.has-feedback-custom {
  // Enable absolute positioning
  position: relative;

  // Ensure icons don't overlap text
  .form-control {
    padding-right: ($input-height-base * 1.25);
  }
}

// Feedback icon (requires .glyphicon classes) //Note: Did not look in to the effect of .glyphicon.
.form-control-feedback-custom {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2; // Ensure icon is above input groups
  display: block;
  width: $input-height-base;
  height: $input-height-base;
  line-height: $input-height-base;
  text-align: center;
  pointer-events: none;
}

// Reposition feedback icon if input has visible label above
.has-feedback-custom label {

  & ~ .form-control-feedback-custom {
    //top: ($line-height-computed + 5); // Height of the `label` and its margin
    top: 32px; //TODO: compute with bootstrap 4 variables.
  }
  &.sr-only ~ .form-control-feedback-custom {
    top: 0;
  }
}

@milanvdm
Copy link

Thanks a lot, that makes a lot of sense.

Could you explain a bit more in detail what you mean with the bootstrap 4 variables? As I would like to adapt it to a fully working sccs file for Bootstrap 4.

@ghost
Copy link

ghost commented Feb 22, 2017

@kezkankrayon

So I currently calculated the variables as follows based on the bootstrap 3 LESS (http://getbootstrap.com/customize/):

@import "../../../../node_modules/bootstrap/scss/variables";

$line-height-computed: floor(($font-size-base * $line-height-base));
$padding-base-vertical: 1rem;
$input-height-base: ($line-height-computed + ($padding-base-vertical * 2) + 2);

But this puts the eye quite a lot under the form.

Im curious on how those variables could be calculated correctly using bootstrap 4 and scss?
As using your values for the variables results in a good solution, it is not fully responsive of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests