如何解决如何在Bootstrap的文本框形式旁边放置帮助图标?
我用帮助文本图标模拟了表单引导程序,如下所示:
但是,我很难在文本字段旁边放置帮助图标,我的尝试结果如下
<!doctype html>
<html lang="en">
<head>
<!-- required Meta tags -->
<Meta charset="utf-8">
<Meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZonixN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<title>Hello,world!</title>
</head>
<body>
<form>
<div class="form-group row">
<label for="colFormlabelSm" class="col-sm-2 col-form-label col-form-label-sm text-right">First Name (English)</label>
<div class="col-sm-5">
<input type="email" class="form-control form-control-sm" id="colFormlabelSm">
<i class="fa fa-question-circle" aria-hidden="true"></i>
</div>
</div>
</form>
<!-- Optional JavaScript -->
<!-- jQuery first,then Popper.js,then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
</html>
有什么办法可以使我的帮助图标正确对齐,如引导程序所示吗?谢谢
解决方法
首先将自定义选择器添加到div
容器中,以包装您的输入和图标(类“ 信息输入”):
<div class="col-sm-5 info-input">
<input type="email" class="form-control form-control-sm" id="colFormLabelSm">
<i class="fa fa-question-circle" aria-hidden="true"></i>
</div>
接下来,我们使用flex将输入和图标对齐在居中的行中
.info-input {
display: flex;
align-items: center;
}
要在输入和图标之间增加一些间距,可以在图标上添加一些空白:
.info-input .fa {
margin-left: 10px;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。