Reputation: 3969
I have a snippet code:
<div class="container" style="margin: 50px">
<div class="form-group">
<span class="fa fa-search form-control-icon"></span>
<input type="text" class="form-control" placeholder="Search">
</div>
</div>
.form-group .form-control {
padding-left: 2.375rem;
}
.form-group .form-control-icon {
position: absolute;
z-index: 2;
display: block;
width: 2.375rem;
height: 2.375rem;
line-height: 2.375rem;
text-align: center;
pointer-events: none;
color: #aaa;
}
How to change the current CSS to have the icon on the right side?
Seems padding-right: 2.375rem;
is not sufficient.
Upvotes: 0
Views: 3308
Reputation: 6887
Since you are using position absolute, you need to define the parent element as position:relative.
Also you need to define the right and top position for it to fix.
.form-group .form-control {
padding-left: 2.375rem;
}
.form-group{
position:relative;
}
.form-group .form-control-icon {
position: absolute;
z-index: 2;
display: block;
width: 2.375rem;
height: 2.375rem;
line-height: 2.375rem;
text-align: center;
pointer-events: none;
color: #aaa;
right:0;
top: 0px;
}
Working jsfiddle link https://jsfiddle.net/47up2sax/
Upvotes: 1