如何对齐本身而不是中心中的项目?

时间:2022-05-29 20:04:05

When i use this snippet code

当我使用这个代码片段时

<h:panelGrid id="myGrid" columns="1"
rendered="#{myBean.showResults}" width="50%"
border="1" style="text-align: center;">  

The items of the panelGrid will be centralized
BUT
I want to centralize h:panelGrid itself in the center of the my XHTML page
Like this HTML code

panelGrid的项将是集中的,但是我想将h:panelGrid本身集中在XHTML页面的中心,就像这个HTML代码一样

<table id="myGrid" border="1" align="center">

2 个解决方案

#1


8  

Provided that it has a known width, give it a left and right margin of auto. This way it will center itself relative to the parent block element.

如果它有一个已知的宽度,给它一个左右的自动边距。这样,它就会相对于父块元素居中。

<h:panelGrid ... style="margin: 0 auto;">

See also:

#2


0  

wrap it in a panelgrid that has the size of your page and set the style of the parent grid to text-align center. Then your child grid will be centered on page (remove the text-align: center style from your child panelgrid

将它封装到具有页面大小的窗格网格中,并将父网格的样式设置为文本对齐中心。然后子网格将集中在页面上(从子窗格网格中删除文本对齐:居中样式)

#1


8  

Provided that it has a known width, give it a left and right margin of auto. This way it will center itself relative to the parent block element.

如果它有一个已知的宽度,给它一个左右的自动边距。这样,它就会相对于父块元素居中。

<h:panelGrid ... style="margin: 0 auto;">

See also:

#2


0  

wrap it in a panelgrid that has the size of your page and set the style of the parent grid to text-align center. Then your child grid will be centered on page (remove the text-align: center style from your child panelgrid

将它封装到具有页面大小的窗格网格中,并将父网格的样式设置为文本对齐中心。然后子网格将集中在页面上(从子窗格网格中删除文本对齐:居中样式)