我正在使用Bootsnip中的css,并且运行良好,但是,当我尝试添加带有图标的帮助块时,它无法按预期运行。
没有图标的帮助块(输入后添加了以下代码):
<label class="help-block">* Required Field</label>
带图标的帮助块(输入后添加了以下代码):
<label class="help-block glyphicon glyphicon-info-sign">* Required Field</label>
在css内部,它确实清除了浮动,因此不确定为什么仍会弄乱。
.icon-addon:after { clear: both; }
最佳答案
我想到了。您正在将标签放置在输入字段之后。错了您需要将标签放置在<div class="icon-addon ... " ... > ... </div>
元素之后。
显示给您:(JSFiddle)
.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;
}
<!--LIBRARIES USED BY BOOTSNIP:-->
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!--REQUIRED LIBRARY USED BY BOOTSNIP:-->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group">
<div class="icon-addon addon-lg">
<input type="text" placeholder="Email" class="form-control" id="email"><label for="email" class="glyphicon glyphicon-search" rel="tooltip" title="email"></label>
</div>
<!--HERE:-->
<!--HERE:-->
<div align="left">
<label class="help-block glyphicon glyphicon-info-sign">*<span style="font-family:Arial"> This is a Required Field (align="left")</span></label>
</div>
<!--HERE:-->
<!--HERE:-->
<div class="icon-addon addon-lg">
<input type="text" placeholder="Email" class="form-control" id="email"><label for="email" class="glyphicon glyphicon-search" rel="tooltip" title="email"></label>
</div>
<!--HERE:-->
<!--HERE:-->
<div align="center">
<label class="help-block glyphicon glyphicon-info-sign">*<span style="font-family:Arial"> This is a Required Field (align="center")</span></label>
</div>
<!--HERE:-->
<!--HERE:-->
<div class="icon-addon addon-lg">
<input type="text" placeholder="Email" class="form-control" id="email">
<!--NOT HERE:-->
<!--NOT HERE:-->
<!--NOT HERE:-->
<label for="email" class="glyphicon glyphicon-search" rel="tooltip" title="email"></label>
</div>
<!--HERE:-->
<!--HERE:-->
<div align="right">
<label class="help-block glyphicon glyphicon-info-sign">*<span style="font-family:Arial"> This is a Required Field (align="right")</span></label>
</div>
<!--HERE:-->
<!--HERE:-->
</div>
关于html - 带图标的Bootstrap帮助块弄乱了表单,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35617868/