Bootstrap: has-feedback on a form-group does not render correctly if the label on the form-group is not specified or removed

Created on 28 Feb 2014  路  8Comments  路  Source: twbs/bootstrap

When using the has-feedback class on a form and if the label on the form group is not specified then it does not render correctly.

<form>
    <div class="form-group has-success has-feedback">
        <input type="text" class="form-control" id="inputSuccess2"> 
        <span class="glyphicon glyphicon-ok form-control-feedback"></span>
    </div>
</form>

The above code renders like this.

bootstrap_feedback_issue

css docs

Most helpful comment

This is similarly broken if the label has more than 1 line

All 8 comments

Not labeling your form fields is bad practice to begin with.

@cvrebert, how abt this

<form>
    <div class="form-group has-success has-feedback">
        <label class="control-label sr-only" for="inputSuccess2">Input with success</label>
        <input type="text" class="form-control" id="inputSuccess2"> 
        <span class="glyphicon glyphicon-ok form-control-feedback"></span>
    </div>
</form>

This also has the same output

FWIW, .has-feedback .form-control-feedback { top: 1px; } seems to be a decent workaround in such a case.
Still, seems kinda niche. Omitting the label could make sense in a .form-inline, but the icon already displays correctly in that case.

A somewhat interesting use case is given in #12911.

Yeah, there's no way to know if the label is there or not in a reliable, performant, and non-shitty way. Using a specific override as you need is the only way this scales beyond our initial styles.

We should document that a label is required.

For those using sr-only, overriding top with the sibling selector (~) seems to work:

.has-feedback label.sr-only ~ .form-control-feedback {
    top: 0;
}

This has the benefit of allowing has-feedback form-groups with non-sr-only labels to still display feedback correctly.

This is similarly broken if the label has more than 1 line

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IamManchanda picture IamManchanda  路  3Comments

kamov picture kamov  路  3Comments

eddywashere picture eddywashere  路  3Comments

cvrebert picture cvrebert  路  3Comments

matsava picture matsava  路  3Comments