Each PrimeFaces theme has a specific font family and font size, which can differ from theme to theme. This may have a disadvantage in a multi-theme application because switching from one theme to another would cause a broken layout. Furthermore, default font sizes of themes might be bigger than expected. Hence, it is important to know how to change font properties of the PrimeFaces components globally.
In this recipe, we will learn how to adjust the font family and font size throughout the web application.
A simple way to change fonts globally can be accomplished by using the .ui-widget
style class. An example of smaller font is as follows:
.ui-widget, .ui-widget .ui-widget { font-size: 90% !important; }
This might not be enough in some cases, especially when you mix PrimeFaces and JSF standard components based on native HTML pendants. In this case, more CSS selectors are required to be listed in order to adjust fonts globally. Assume that we have decided to use the font Arial with size as 12 pixel. CSS selectors working for all known components would be as in the following code:
body, input, select, textarea, button, .ui-widget, .ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button, .ui-widget-header, .ui-widget-content, .ui-widget-header .ui-widget-header, .ui-widget-content .ui-widget-content { font-family: Arial, Verdana, sans-serif; font-size: 12px !important; }
All PrimeFaces components are styled by the ui-widget
style class. It is a skinning style specified by jQuery ThemeRoller and applied to HTML elements rendered by PrimeFaces. An input element has it, for instance:
<input type="text" class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" name="..." id="..." role="textbox">
In rare cases, when some component parts have been assigned font properties, but are not styled by .ui-widget
or you use non-PrimeFaces components, more CSS selectors are needed for changing font properties throughout the web application.
52.15.129.90