BumbleBee BumbleBee - 6 months ago 15
HTML Question

Display Icons inside a text box

I need the following controls in one line and aligned right. I need the two icons appear inside the textbox at the right corner. And also both the controls to be aligned right.

Here is the Plunker

<div class="col-md-12">
<div class="col-md-6">
<input type="text" id="txtDateRange"
class="form-control input-md" name="txtDateRange"
placeholder="Select Range"
ng-model="Model.RageDates" />
<span><i class="glyphicon glyphicon-remove" ></i></span>

<span class="form-control-feedback"><i class="glyphicon glyphicon-calendar fa fa-calendar"></i></span>

</div>

<div class="col-md-6" style="float: right;">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span>{{ selectedItem ? selectedItem.Label : 'ALL LOCATIONS' }}</span>
<span class="caret"></span>
</button>

<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li ng-repeat="Label in Summary.Locations">
<a ng-click="dropboxitemselected(Label)">
{{Label.Label}}
</a>
</li>
</ul>
</div>

</div>

Answer

Bootstrap styles .form-control input elements as BLOCK (they are usually inline).

If you restyle that specific input element to inline-block and reduce the width a bit (unsure why that was necessary - perhaps only for SO snippet environment), you will be able to use margin-left on the span elements to walk them over a bit.

span.a1{margin-left:-50px;border:1px solid green;}
span.a2{border:1px solid red;}

#txtDateRange{display:inline-block;width:99.3%;}
div.a1 {display:inline-block;margin-left:-50px;border:1px solid green;}
div.a2 {display:inline-block;                  border:1px solid red;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<p>&nbsp;</p>
<div class="col-md-12">
  <div class="col-md-6">
    <input type="text" id="txtDateRange"
           class="form-control input-md" name="txtDateRange"
           placeholder="Select Range"
           ng-model="Model.RageDates" />
    <span class="a1"><i class="glyphicon glyphicon-remove" ></i></span>
    <span class="a2 xform-control-feedback"><i class="glyphicon glyphicon-calendar xfa xfa-calendar"></i></span>

  </div>

  <div class="col-md-6" style="float: right;">
    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      <span>{{ selectedItem ? selectedItem.Label : 'ALL LOCATIONS' }}</span>
      <span class="caret"></span>
    </button>

    <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
      <li ng-repeat="Label in Summary.Locations">
        <a ng-click="dropboxitemselected(Label)">
          {{Label.Label}}
        </a>
      </li>
    </ul>
  </div>

</div>