最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add an icon inside a textfield - Stack Overflow

programmeradmin0浏览0评论

I have a search textfield in my toolbar. I want to add an image inside textfield (search icon at the left most) instead of some text.

Please provide some ideas to achieve this.

I have a search textfield in my toolbar. I want to add an image inside textfield (search icon at the left most) instead of some text.

Please provide some ideas to achieve this.

Share Improve this question edited Nov 8, 2015 at 8:10 Tarabass 3,1502 gold badges19 silver badges35 bronze badges asked May 12, 2015 at 10:50 SWATI GUPTASWATI GUPTA 431 silver badge10 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 8

I would remend you use font-awesome to load your icons. Once the Font Awesome library has been added, you should do something like this:

Fiddle: https://fiddle.sencha./#fiddle/mmp

Ext.create('Ext.Panel',{
    renderTo: Ext.getBody(),
    width: 500,
    height: 500,
    title: 'Testing Panel',
    html : 'Contents of the Testing Panel',
    bodyPadding: 10,
    tools:[{
        xtype : 'textfield',
        fieldStyle : 'font-family: FontAwesome',
        emptyText: '\uF002 Find User'
    }]
});

In my situation, I needed the icon to always be present, so this is the solution I came up with (Fiddle):

JS

Ext.create('Ext.Panel', {
    renderTo: Ext.getBody(),
    width: 500,
    height: 500,
    title: 'Testing Panel',
    html: 'Contents of the Testing Panel',
    bodyPadding: 10,
    tools: [{
        xtype: 'textfield',
        cls: 'icon-textfield fa fa-search',
        emptyText: 'Find User'
    }]
});

CSS

.icon-textfield:before {
    position: absolute;
    height: 100%;
    z-index: 9999;
    left: 5px;
    font-size: 12px;
    top: 25%;
}

.icon-textfield .x-form-text {
    padding-left: 20px;
}
发布评论

评论列表(0)

  1. 暂无评论