9
votes

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?

2

2 Answers

11
votes

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'
        }
    ]
});
3
votes

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'
    }]
});