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

javascript - extjs 4.2.1 - center align text in label - Stack Overflow

programmeradmin0浏览0评论

I have a Ext.form.Label ponent in ExtJS. In the label I have 2 lines of text. How do I horizontally center both of these lines of text? For example:

ABC
 B

I tried putting span tags around each line and styling them with text-align:center but both of the text are still left aligned.

EDIT: added some code:

label.update('<span>ABC</span><br>'+
             '<span>B</span>');

I have a Ext.form.Label ponent in ExtJS. In the label I have 2 lines of text. How do I horizontally center both of these lines of text? For example:

ABC
 B

I tried putting span tags around each line and styling them with text-align:center but both of the text are still left aligned.

EDIT: added some code:

label.update('<span>ABC</span><br>'+
             '<span>B</span>');
Share Improve this question edited Jan 7, 2014 at 22:31 Android Noob asked Jan 7, 2014 at 22:08 Android NoobAndroid Noob 3,3414 gold badges37 silver badges60 bronze badges 1
  • using html instead of text in Ext.form.label – John Paul Cárdenas Commented Jan 7, 2014 at 22:37
Add a ment  | 

3 Answers 3

Reset to default 5

Thanks for all the answer guys. I figured it out:

label.setText('ABC<br/>B');

Then in your label config, you simply define the style property like this:

style: 'display:inline-block;text-align:center'

I don't know what you are exctly trying to do, do you have some code? To center things with spans, the spans must be the same width, so add this to your css code:

display:inline-block;
width:40px;

The display:inline-block; is because normal spans don't accept widths.

See this jsfiddle

adding the span to the fieldLabel config of the textfield works.

You will need to uses display:inline-block because ExtJs adds a ":" at the end of your label.

   {
        xtype: 'textfield',
        name: 'email',
        fieldLabel: '<span style="display:inline-block; text-align:center;">Really long top<br/>small</span>',
    }

working example: http://jsfiddle/eLnu5/

发布评论

评论列表(0)

  1. 暂无评论