Adjusting the font and size throughout the web application

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.

How to do it…

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;
}

Note

Using !important in CSS can sometimes be useful to force a rule, so that you can place your CSS in any order in HTML.

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;
}

Note

The universal selector * is much shorter, but it has no CSS specificity. Its specificity is 0,0,0,0. That means, it cannot overwrite, for example, an inline style with a specified font size.

How it works…

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.

See also

  • More explanation for CSS selectors in the PrimeFaces-based applications can be found in the Understanding structural and skinning CSS and Customizing default theme styles recipes
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.129.90