公告
财富商城
积分规则
提问
发文
2019-01-01 06:45发布
深知你不懂我心
How do I put an icon inside a form's input element?
Live version at: Tidal Force theme
Just use the background property in your CSS.
<input id="foo" type="text" /> #foo { background: url(/img/foo.png); }
A solution without background-images:
#input_container { position:relative; padding:0 0 0 20px; margin:0 20px; background:#ffffd; direction: rtl; width: 200px; } #input { height:20px; margin:0; padding-right: 30px; width: 100%; } #input_img { position:absolute; bottom:2px; right:5px; width:24px; height:24px; }
<div id="input_container"> <input type="text" id="input" value> <img src="https://cdn4.iconfinder.com/data/icons/36-slim-icons/87/calender.png" id="input_img"> </div>
.icon{ background: url(1.jpg) no-repeat; padding-left:25px; }
add above tags into your CSS file and use the specified class.
You can try this:
input[type='text'] { background-image: url(images/comment-author.gif); background-position: 7px 7px; background-repeat: no-repeat; }
<label for="fileEdit"> <i class="fa fa-cloud-upload"> </i> <input id="fileEdit" class="hidden" type="file" name="addImg" ng-file-change="onImageChange( $files )" ng-multiple="false" accept="{{ contentType }}"/> </label>
For example you can use this : label with hidden input (icon is present).
I find this the best and cleanest solution to it. Using text-indent on the input element
input
CSS:
#icon{ background-image:url(../images/icons/dollar.png); background-repeat: no-repeat; background-position: 2px 3px; }
HTML:
<input id="icon" style="text-indent:17px;" type="text" placeholder="Username" />
最多设置5个标签!
Just use the background property in your CSS.
A solution without background-images:
add above tags into your CSS file and use the specified class.
You can try this:
For example you can use this : label with hidden input (icon is present).
I find this the best and cleanest solution to it. Using text-indent on the
input
elementCSS:
HTML: