【问题标题】:Align buttons in the middle of a container with ExtJS 4使用 ExtJS 4 对齐容器中间的按钮
【发布时间】:2013-12-04 14:42:31
【问题描述】:

问题很简单。 我有一个主屏幕,北部地区必须显示两个文本字段和一个按钮以使用户能够连接。

我有这个代码。

Ext.create('Ext.container.Viewport', {
    layout: 'anchor',
    id: 'homescreen', 
    items: [
        {    
            layout: 'border',
            border: false,
            height: 160,
            anchor: '100%',
            items: [
                {
                region: 'west',
                // some codes here
                },
                {
                xtype: 'container',
                width: '70%',
                region: 'east',
                layout: 
                    {
                    type: 'table',

                    columns: 1,
                    tdAttrs: 
                        { 
                        style: 'padding: 5px 15px 5px 15px;',
                        align: 'middle',
                        },
                    defaults: 
                        {
                        width: 150,
                        textAlign: 'right'
                        },
                    },
                    items: [
                        {
                        xtype: 'textfield',
                        //fieldLabel: 'login',
                        labelWidth:50,
                        emptyText: 'Utilisateur',
                        margin: '18 0 0 0',

                        },
                        {
                        xtype: 'textfield',
                        //fieldLabel: 'mot de passe',
                        labelWidth:100,
                        emptyText: 'Mot de passe',

                        },
                        {
                        xtype: 'button',
                        html: 'Connexion',
                        scale: 'large',
                        },
                    ]
            }]

        }, 

如您所见,所有文本字段和按钮都垂直对齐在一列上。 但问题是它们显示在容器的左侧。如何在右侧显示它们(不使用 css)? =
水平对齐。

【问题讨论】:

    标签: extjs extjs4 alignment


    【解决方案1】:

    VBox layout 可能更适合您的用例。它垂直堆叠组件并让您控制生成块的水平和垂直对齐方式。

    试试下面的布局,例如:

    layout: {
        type: 'vbox'
        ,align: 'center' // or 'right'
        ,pack: 'center' // controls vertical align
        ,defaultMargins: 5
    }
    

    【讨论】:

    • 而不是表格布局?
    • @SecularKid 是的,用这个替换你自己的布局配置,然后玩它。这是我最喜欢的布局之一,它适合许多用例。我很高兴它被集成到 CSS3 中:)
    • @rixo 还不错。只是个人喜好问题。只要您坚持下去(至少在相同的文件中)。 SecularKid 尝试在 vbox 和 hbox 中使用“start”、“center”、“end”(start 表示左侧或顶部)。 docs
    • pack 的可能值是“开始”、“中心”或“结束”(请参阅​​docs)。如果您希望字段及其容器具有不同的对齐方式(例如,将字段向右对齐,但在它们之间保持它们与左侧对齐),您必须将它们嵌套到另一个容器中。您应该使用form layout 作为字段容器,使用hbox 作为其父容器。
    • Saki is bada$$,在自动 linting 工具如此广泛使用之前,前导逗号已经存在 :)
    猜你喜欢
    • 1970-01-01
    • 2013-02-08
    • 2013-02-07
    • 2020-08-22
    • 2019-09-23
    • 2010-10-30
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多