Abhishek Abhishek - 5 months ago 26
CSS Question

How to align JSF components to center

In my JSF 2 - Primefaces 3 web application, I am using

<p:panelGrid>
and
<p:panel>
. I have multiple components inside them which are left justified. I need to all to be center align. How can we do this I tried to use div but it does not work.

Answer

Look at the generated HTML output and alter CSS accordingly.

If the HTML element which you'd like to center is a block element (<div>, <p>, <form>, <table>, etc, or forced by display: block;), then you first need to give it a known width and then you can center it relative to its parent block element using CSS margin: 0 auto; on the element itself.

If the HTML element which you'd like to center is an inline element (<span>, <label>, <a>, <img>, etc, or forced by display: inline;), then you can center it using CSS text-align: center; on its parent block element.