<p:panel style="height:500px;position:relative;"/>
<p:panelGrid columns="1" styleClass="centered">
<div class="component-spacing-top"/>
<h:graphicImage alt="#{business.businessName}" value="#{business.logoFullPath}" class="small-panel-image" />
<div class="component-spacing-top"/>
</p:panelGrid>
</p:panel>
height
值是隨機給出不要緊,但不要抹去position:relative
。
.centered {
position: absolute;
height: 100px;
top: 0;
bottom: 0;
margin:auto;
}
對於水平應該下方添加規則:
left:50%;margin-left:-100px;width:200px;
看出來,margin-left
值是width
值的-1/2倍。
結果:
如果width
是不固定的,你可以試試這個方式,它適用於我和對齊它在同時水平和垂直中心:
<p:panel style="line-height:200px;padding: 5% 0;position: relative;"/>
<p:panelGrid columns="1" styleClass="centered">
<div class="component-spacing-top"/>
<h:graphicImage style="vertical-align:middle;" alt="#{business.businessName}" value="#{business.logoFullPath}" class="small-panel-image" />
<div class="component-spacing-top"/>
</p:panelGrid>
</p:panel>
注該graphicImage也具有style
屬性。
.centered {
position:relative;
height: 100px;
margin:0 auto;
padding: 10% 0;
}
結果:
即使不工作,你應該檢查,我給裏面about
的鏈接。那是我在這裏做的6種方式,你應該混合它們。
我試過兩個,沒有工作。 – 2013-05-05 08:39:14
@Abhishek無論如何,它可以用這種方式再次檢查出來嗎? – 2013-05-05 09:29:33
是的,這種方式垂直對齊工作,但列出水平對齊。 – 2013-05-05 10:00:36