Skip to content

Instantly share code, notes, and snippets.

@lightstrike
Last active August 29, 2015 14:05
Show Gist options
  • Save lightstrike/d3d0a653511638ede586 to your computer and use it in GitHub Desktop.
Save lightstrike/d3d0a653511638ede586 to your computer and use it in GitHub Desktop.
Embedded Icon in Bootstrap 3 Input
<!--
See http://codepen.io/lightstrike/pen/tswme for demo
Example markup and inspiration from http://jsfiddle.net/KyleMit/cyCFS/
-->
<p>Full Size:</p>
<div class="left-inner-addon ">
<i class="glyphicon glyphicon-user"></i>
<input type="text"
class="form-control"
placeholder="Username" />
</div>
<div class="right-inner-addon ">
<i class="glyphicon glyphicon-search"></i>
<input type="search"
class="form-control"
placeholder="Search" />
</div>
<br/>
<p>Smaller:</p>
<div class="col-xs-6" >
<div class="left-inner-addon">
<i class="glyphicon glyphicon-user"></i>
<input type="text"
class="form-control"
placeholder="Username" />
</div>
</div>
<div class="col-xs-6" >
<div class="right-inner-addon">
<i class="glyphicon glyphicon-search"></i>
<input type="search"
class="form-control"
placeholder="Search" />
</div>
</div>
/* Inspiration from http://jsfiddle.net/KyleMit/cyCFS/ */
@mixin inputAddon($position, $padding:9px, $iconAttr:"i", $inputAttr:"input") {
position: relative;
#{$iconAttr} {
position: absolute;
#{$position}: 0;
padding: $padding;
pointer-events: none;
}
#{$inputAttr} {
width: 100%;
padding-#{$position}: 30px;
}
}
.left-inner-addon {
@include inputAddon("left");
}
.right-inner-addon {
@include inputAddon("right");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment