带有图标的Bootstrap帮助块会弄乱表单

时间:2016-02-25 03:47:15

标签: html css twitter-bootstrap icons

我正在使用此Bootsnip中的css并且它运行良好,但是,当我尝试添加带有图标的帮助块时,它无法按预期工作。

帮助阻止没有图标(输入后添加以下代码):

<label class="help-block">* Required Field</label>

enter image description here

帮助阻止w /图标(输入后添加以下代码):

<label class="help-block glyphicon glyphicon-info-sign">* Required Field</label>

enter image description here

在CSS中,它确实清除浮动,所以不确定它为什么还在弄乱。

.icon-addon:after { clear: both; }

2 个答案:

答案 0 :(得分:0)

我明白了。您正在输入字段后面放置标签。这是错的。您需要将标签放在object.id元素之后。

向您展示:(JSFiddle

&#13;
&#13;
<div class="icon-addon ... " ... > ... </div>
&#13;
.center-block {
    float: none;
    margin-left: auto;
    margin-right: auto;
}

.input-group .icon-addon .form-control {
    border-radius: 0;
}

.icon-addon {
    position: relative;
    color: #555;
    display: block;
}

.icon-addon:after,
.icon-addon:before {
    display: table;
    content: " ";
}

.icon-addon:after {
    clear: both;
}

.icon-addon.addon-md .glyphicon,
.icon-addon .glyphicon, 
.icon-addon.addon-md .fa,
.icon-addon .fa {
    position: absolute;
    z-index: 2;
    left: 10px;
    font-size: 14px;
    width: 20px;
    margin-left: -2.5px;
    text-align: center;
    padding: 10px 0;
    top: 1px
}

.icon-addon.addon-lg .form-control {
    line-height: 1.33;
    height: 46px;
    font-size: 18px;
    padding: 10px 16px 10px 40px;
}

.icon-addon.addon-sm .form-control {
    height: 30px;
    padding: 5px 10px 5px 28px;
    font-size: 12px;
    line-height: 1.5;
}

.icon-addon.addon-lg .fa,
.icon-addon.addon-lg .glyphicon {
    font-size: 18px;
    margin-left: 0;
    left: 11px;
    top: 4px;
}

.icon-addon.addon-md .form-control,
.icon-addon .form-control {
    padding-left: 30px;
    float: left;
    font-weight: normal;
}

.icon-addon.addon-sm .fa,
.icon-addon.addon-sm .glyphicon {
    margin-left: 0;
    font-size: 12px;
    left: 5px;
    top: -1px
}

.icon-addon .form-control:focus + .glyphicon,
.icon-addon:hover .glyphicon,
.icon-addon .form-control:focus + .fa,
.icon-addon:hover .fa {
    color: #2580db;
}
&#13;
&#13;
&#13;

答案 1 :(得分:0)

这可以帮助

<label class="help-block"><span class="glyphicon glyphicon-info-sign"></span>* Required Field</label>