Icon textboxes allow you to add an icon to a textbox, adding a little flair to a boring textbox.
To create an icon textbox, you will want to start with a wrapper div that has the icon-textbox
class. Next, add a Bootstrap icon element. Make sure to add the icon
class to the icon. Finally, add a form-control
text input box.
<div class="icon-textbox">
<span class="icon bi-telephone"></span>
<input type="text" class="form-control" placeholder="Phone number" />
</div>
You can place the icon to the right of the textbox by putting it after the <input>
element:
<div class="icon-textbox">
<input type="text" class="form-control" placeholder="Phone number" />
<span class="icon bi-telephone"></span>
</div>
You can scale an icon textbox by changing the font-size of the icon-textbox
div.
<div class="icon-textbox" style="font-size: 25px">
<span class="icon bi-telephone"></span>
<input type="text" class="form-control" placeholder="Phone number" />
</div>
<div class="icon-textbox" style="font-size: 10px">
<span class="icon bi-telephone"></span>
<input type="text" class="form-control" placeholder="Phone number" />
</div>
Icon textboxes are compatible with NS-Lib floating labels:
Usage is pretty simple - simply create one wrapper div that has both the icon-textbox
and floating-labels
classes. Then, add your icon, textbox, and label inside the wrapper div.
<div class="icon-textbox floating-labels">
<i class="icon bi-search"></i>
<input type="text" class="form-control" placeholder="" />
<label>Search</label>
</div>
You can also use a right-aligned icon, but you need to add the icon-textbox-right
class to the parent div for the spacing to work correctly.
<div class="icon-textbox icon-textbox-right floating-labels">
<input type="text" class="form-control" placeholder="" />
<label>Search</label>
<i class="icon bi-search"></i>
</div>
Icon textboxes are also compatible with Bootstrap spinners. This is great if you want to show the user that you are waiting on something.
To implement a spinner, just put a Bootstrap spinner inside of the icon element.
<div class="icon-textbox">
<span class="icon"><span class="spinner-border"></span></span>
<input type="text" class="form-control" placeholder="Loading..." />
</div>