9

I am trying to align mid of the screen of an item simply a label but it is aligning it horizontally not vertically.

var panel = new Ext.Panel({
    layout:{
        type: 'vbox',
        align: 'center'
    },
    items:[
        {
            xtype: 'label',
            html: 'My Label'
        }
    ],
    fullscreen: true,
    flex: 1
});

I have removed flex, and set height as well, but it doesn't work. Please give me some clue?

MarthyM
  • 1,839
  • 2
  • 21
  • 23
sohail.hussain.dyn
  • 1,411
  • 1
  • 16
  • 26

2 Answers2

13

Try using pack: center in the layout, like this:

var panel = new Ext.Panel({
    layout: {
        type: 'hbox',
        align: 'center',
        pack: 'center'
    }, 
    items:[
        {
            xtype: 'label',
            html: 'My Label'
        }
    ]
});
MarthyM
  • 1,839
  • 2
  • 21
  • 23
Sujata Chanda
  • 3,355
  • 2
  • 21
  • 35
4

For HBox layout preferable to use 'align: middle' config I suppose. Try this:

var panel = new Ext.Panel({
    layout: {
        type: 'hbox',
        align: 'middle'
    }, 
    items:[{
        xtype:'label',
        html:'My Label'
    }]
});
Alex Dzeiko
  • 866
  • 11
  • 12