【问题标题】:Center component on jsf pagejsf页面中心组件
【发布时间】:2014-08-10 11:20:07
【问题描述】:

我试图将组件放在 jsf 页面的中心,它看起来像这样:

<p:panel header="Enter your credentials:" style="vertical-align:middle;">

    <h:panelGrid columns="2" styleClass="panelGridCenter">
                <h:outputText value="Login: " />
                <p:inplace id="Login">
                    <p:inputText value="Enter login" />
                </p:inplace>
            </h:panelGrid>
    </p:panel>

我试过这样输入:

style="vertical-align:middle;"

我尝试过使用 css 类(我几乎没有 css 经验):

.panelGridCenter {
      margin: 0 auto;
      vertical-align:middle;
}

但它不起作用。 您能给我一些示例或提示如何将此组件(面板)放置在 jsf 页面的中心吗?

p - 素面

提前谢谢

【问题讨论】:

    标签: html css jsf jsf-2 primefaces


    【解决方案1】:

    我不是专家,但分享我自己的经验。将面板放入表单后,尝试将表单放入 div 中,样式如下:

    <div style="width:360px; margin: 10% auto 10% auto;">
    <h:form>
        ....
    </h:form>
    </div>
    

    【讨论】:

    • 请根据问题需要修改答案。
    【解决方案2】:

    这可能无关紧要,因为我无法回答您的问题,但一个对话框(默认居中)对于登录页面来说看起来很酷:

        <h:body>
            <p:growl id="growl" life="5000" autoUpdate="true" showDetail="true" escape="false"/>
    
            <h:form>    
                <p:dialog id="dialog" header="Login" footer="..." width="400" widgetVar="dlg" visible="true" closable="false" showEffect="clip" draggable="false" resizable="false" style="box-shadow: 7px 10px 5px #303030;"> 
    
                        <p:panelGrid columns="2" style="margin: 0 auto">
                            <h:outputText value="username:"/>            
                            <h:inputText value="#{loginBean.username}" id="username"/>            
                            <h:outputText value="password:"/>            
                            <h:inputSecret value="#{loginBean.password}" id="password"/>            
                        </p:panelGrid>
                        <p:commandButton  id="button" value="Login" action="#{loginBean.doLogin}" style="float:right"/>            
    
                </p:dialog>
            </h:form>   
        </h:body>
    

    visible="true" 使对话框在加载后自动显示。

    this 文章启发,还展示了如何保护应用程序的某些部分。

    【讨论】:

    • 是的,它看起来很不错:)
    【解决方案3】:

    试试下面的代码我希望这个答案是你的问题

    <h:form>            
            <table width="100%" cellpadding="0" cellspacing="0" border="0" align="center"  class="outer_table">
                <tr>
                    <td>
                        <table width="500" height="300" cellpadding="0" cellspacing="0" border="0" align="center">
                            <tr>
                                <td align="center">
                                    <p:panel header="Login">
                                        <h:panelGrid columns="2" cellpadding="5">
    
                                            <h:outputLabel for="username" value="username" />
                                            <p:inputText id="username" value="#{loginBean.uname}" required="true" label="username"/>
    
                                            <h:outputLabel for="password" value="password" />
                                            <p:password id="password" value="#{loginBean.password}" required="true" label="password" />
    
                                            <p:commandButton value="Login"  action="#{loginBean.loginProject}" update=":growl"/>
    
                                        </h:panelGrid>
                                    </p:panel>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </h:form>
    

    css

    <script type="text/css">
        html, body
        {
            margin:0px;
            padding:0px;
            width:100%;
            min-height:100%;
            height:100%;
        }
        .outer_table
        {
            width:100%;
            height:100%;
        }
    </script>
    

    【讨论】:

    • 我用过这个css类:.loginPanel { position: relative;最高:50%;边距顶部:150px;高度:150px;左:50%;左边距:-180px;宽度:360px;背景颜色:#BFFFFE; } ,但直到我添加
    猜你喜欢
    • 2012-07-10
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多