[转]Add Bootstrap Glyphicon to Input Box
本文转自:http://stackoverflow.com/questions/18838964/add-bootstrap-glyphicon-to-input-box
How can I add a glyphicon to a text type input box? For example I want to have 'icon-user' in a username input, something like this:
576down voteaccepted
|
Without Bootstrap:We'll get to Bootstrap in a second, but here's the fundamental CSS concepts in play in order to do this yourself. As beard of prey points out, you can do this with CSS by absolutely positioning the icon inside of the input element. Then add padding to either side so the text doesn't overlap with the icon. So for the following HTML:
You can use the following CSS to left and right align glyphs:
Demo in Plunker
With Bootstrap:As buffer points out, this can be accomplished natively within Bootstrap by using Validation States with Optional Icons. This is done by giving the The simplest example would be something like this:
Pros:
Cons:
To overcome the cons, I put together this pull-request with changes to support left aligned icons. As it is a relatively large change, it has been put off until a future release, but if you need these features today, here's a simple implementation guide: If you're using less, just include these changes in your project. If you're not using less, grab the file and convert it to CSS with any online LESS Compiler. Then, all you have to do is include the class Since there are a lot of possible html configurations over different form types, different control sizes, different icon sets, and different label visibilities, I created a test page that shows the correct set of HTML for each permutation along with a live demo. Here's a demo in Plunker
Didn't find what you were looking for? Try these similar questions: |
posted on 2017-05-09 11:33 freeliver54 阅读(1549) 评论(1) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步