Incorrect glyphicon sizes in form / .input-group / .input-group-addon inputs in bootstrap 3

怎甘沉沦 提交于 2020-01-13 19:27:11

问题


I am trying to add glyphicons to form input boxes using bootstrap 3.

However, the glyphicons are displayed larger than the input textbox, as can be seen here:

The documentation says Use .input-group with an .input-group-addon to prepend or append elements to a .form-control.

As far as I can tell, I'm doing just this, but I clearly have something wrong, and can't figure out what it is.

Markup and fiddle below:

<div class="jumbotron">
    <h4>Glyphicons, why you no look nice?</h4>
    <form name="form">
        <div class="input-group">
            <span class="input-group-addon glyphicon glyphicon-envelope"></span>
            <input type="email" 
                class="form-control" 
                placeholder="Email" 
                name="email"/>
        </div>                
        <div class="input-group">
            <span class="input-group-addon glyphicon glyphicon-lock"></span>
            <input type="password" 
                class="form-control" 
                placeholder="Password" 
                name="password"/>
        </div>                
    </form>
</div>

Working example on jsfiddle


回答1:


It's because the font-size is being inherited from the 'jumbotron' (21px).

You'll need to explicitly set the font-size on the form or its items.

Also, once you use the glyphicon class, you'll get the top: 1px so you'll need to set that to 0 for the addon to line up with the input.

Here's my updated fiddle.



来源:https://stackoverflow.com/questions/20391366/incorrect-glyphicon-sizes-in-form-input-group-input-group-addon-inputs-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!