4

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

<table id="myGrid" border="1" align="center">
2
  • CAn we see the rendered HTML output? Not everyone knows what a <h:panelGrid> will output ;)
    – Kyle
    Commented Jan 2, 2013 at 9:04
  • Take a look stackoverflow.com/q/3714143/617373
    – Daniel
    Commented Jan 2, 2013 at 9:18

2 Answers 2

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:

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.