Posted under CSS
Permalink
Tags CSS, Gotcha, HTML, Primefaces, Tip
Update 22/09/2011
The following selector (as documented below) did not work when used for a particular table. CSS ignored the rule presumably for reasons of specificity:-
.ss-nested-widget, .ss-nested-widget .ui-datatable {
font-size: 100% !important;
}
However, the following selector did work (and was also modified to include a dialog as well as a table). This has the advantage of not relying on having ss-nested-widget as a class on the table in order to work.
This has now been adopted as standard as the solution for this issue :-
.ss-nested-widget,
.ui-widget .ui-datatable,
.ui-widget .ui-dialog {
font-size:100% !important;
}
Original Post
This issue is due to font size inheritance.
My default font for all Primefaces components was specified globally as follows:-
.ui-widget {
font-size: 75% !important;
}
The reason for this is that in general it is considered more flexible to go for percentage sizes as these can then be scaled automatically when viewed on smaller devices.
Unfortunately, it appears that when for example a table is nested inside a panel, the font size appears to be 75% of 75% as the rule is inherited and applied twice, as 75% is a relative measurement, The table ends up rendered as a 9px font which is too small. The situation is further complicated by the fact that in the Primefaces skinning, there is a mixture of fonts specified in ems, percentages and pixel sizes, which means that not everything is specified in relative sizing anyway.
There are 2 solutions to the issue, both are straightforward, 1/ is the simplest although arguably not the best due to absolute sizing:-
1/ Change the global ui-widget rule above to use a fixed font size (12px works as a replacement for the above 75%)
.ui-widget {
font-size: 12px !important;
}
2/ Keep the 75% for ui-widget and introduce a new rule to specify a 100% size for nested elements:-
.ss-nested-widget {
font-size:100% !important;
}
This rule needs to be introduced inside the panel. If it is placed on the panel itself, which is the parent element, then the font size just ‘goes large’ to 100%, i.e. larger than the desired default font. To obtain the correct behaviour, the sub-elements inside the panel must be tagged with the style class. It is possible to tag an enclosing <div> just inside the panel, so that the sub-elements inherit it. However, whilst this worked for input selectors and buttons in the panel, tables refused to play ball, and the following rule was needed to ensure that a table in the panel inherited the correct size:-
.ss-nested-widget, .ss-nested-widget .ui-datatable {
font-size: 100% !important;
}
The same kind of trick can be used to target other nested elements which do not inherit the correct size.
An alternative method would be just to add the class to sub-elements individually where required.