输入右侧的样式字体真棒图标

时间:2016-01-11 21:11:21

标签: html css twitter-bootstrap font-awesome

很难将此图标强制放在输入的右侧而不是下方。已经更改了编号,放入div等。但没有。以下是它现在的样子:

enter image description here

我的代码是(示例未显示结束表单标记):

    <form class="pptReg" role="form" name="pptReg" novalidate>
        <h1 style="padding-top: 60px; color: #ab2328;">Participant Information</h1>
        <div class="form-group col-md-3 naviaInp" style="padding-top: 30px;">
            <label for="empCode">Employer Code</label>
            <input type="text" name="empCode" class="form-control" id="empCode" data-ng-model="pptregistration.coCode" ng-required="true" maxlength="3" autofocus ng-blur="getEmpIdType(true);">
            <a class="questionIcon" href="#"><i class="fa fa-question-circle col-md-2 fa-2x" style="float: right;"></i></a>
            <div ng-show="(pptReg.$submitted || pptReg.empCode.$touched) && pptReg.empCode.$error.required">
                <p class="claimError"><i class="fa fa-exclamation-circle"></i><span>This is a required field.</span></p>
            </div>
            <div ng-show="(pptReg.$submitted || pptReg.empCode.$touched) && empIdType == ''">
                <p class="claimError"><i class="fa fa-exclamation-circle"></i><span>The Employer Code is invalid.</span></p>
            </div>
        </div>

它只是一个字体真棒图标我试图添加到输入的右侧。我使用Bootstrap 3进行布局。

想法或建议(我自己经历了许多想法!)?

非常感谢。

3 个答案:

答案 0 :(得分:2)

在问号中添加display: inline;

<a class="questionIcon" href="#"><i class="fa fa-question-circle col-md-2 fa-2x" style="float: right; display:inline;"></i></a>

答案 1 :(得分:1)

.form-control 将empCode输入作为块元素。您需要在输入中添加样式以允许其他元素与其位于同一行(即float:left; display:inline-block;)。

答案 2 :(得分:1)

首先,您需要限制输入的宽度,以便图标旁边有足够的空间。然后,您还需要将输入和图标设置为display:inline-block;,从图标中删除col-md-2类,因为它是不必要的。最后,将vertical-align:middle;添加到图标,使其与输入垂直对齐。

<强> HTML:

<form class="pptReg" role="form" name="pptReg" novalidate="">
    <h1 style="padding-top: 60px; color: #ab2328;">Participant Information</h1>
    <div class="form-group col-md-3 naviaInp" style="padding-top: 30px;">
        <label for="empCode">Employer Code</label>
        <input type="text" name="empCode" class="form-control" id="empCode" data-ng-model="pptregistration.coCode" ng-required="true" maxlength="3" autofocus="" ng-blur="getEmpIdType(true);">
        <a class="questionIcon" href="#"><i class="fa fa-question-circle col-md-2 fa-2x"></i></a>
        <div ng-show="(pptReg.$submitted || pptReg.empCode.$touched) &amp;&amp; pptReg.empCode.$error.required">
            <p class="claimError"><i class="fa fa-exclamation-circle"></i><span>This is a required field.</span></p>
        </div>
        <div ng-show="(pptReg.$submitted || pptReg.empCode.$touched) &amp;&amp; empIdType == ''">
            <p class="claimError"><i class="fa fa-exclamation-circle"></i><span>The Employer Code is invalid.</span></p>
        </div>
    </div>
</form>

<强> CSS:

.form-control {
  display:inline-block;
  width:90%;
}
a.questionIcon {
  display:inline-block;
  vertical-align:middle;
}

Bootply