jsf - How do I override default PrimeFaces CSS with custom styles? -
i've created own theme separate maven project, , loaded correctly.
now want change size of component. example, <p:orderlist>
. has class called ui-orderlist-list
defined in primefaces.css
fixed 200x200 dimension. no matter in theme.css
, overwritten attribute , there no way can make content part of <p:orderlist>
wider.
for other components might want override 1 instance of component, not all.
can please tell me how can this?
there several things need take account of 1 or more might relevant specific case
load css after primefaces one
you need ensure css loaded after primefaces one. can achieve placing <h:outputstylesheet>
referencing css file inside <h:body>
instead of <h:head>
:
<h:head> ... </h:head> <h:body> <h:outputstylesheet name="style.css" /> ... </h:body>
jsf automatically relocate stylesheet end of generated html <head>
, ensure stylesheet loaded after primefaces' default styles. way selectors in css file same in primefaces css file precedence on primefaces one.
you'll see suggestions put in <f:facet name="last">
of <h:head>
understood primefaces-specific headrenderer
, unnecessarily clumsy , break when have own headrenderer
.
understand css specificity
you need ensure css selector at least specific primefaces' default css selector on particular element. need understand css specificity , cascading , inheritance rules. example, if primefaces declares style default follows
.ui-foo .ui-bar { color: pink; }
and declare as
.ui-bar { color: purple; }
and particular element class="ui-bar"
happen have parent element class="ui-foo"
, primefaces' 1 still precedence because that's specific match!
you can use webbrowser developer tools find exact css selector. rightclick element in question in webbrowser (ie9/chrome/firefox+firebug) , choose inspect element see it.
partial overriding
if need override style specific instance of component , not instances of same component, add custom styleclass
, hook on instead. case specificity used/applied. example:
<p:datatable styleclass="borderless">
.ui-datatable.borderless tbody, .ui-datatable.borderless th .ui-datatable.borderless td { border-style: none; }
never use !important
in case fail load css file in order or figure right css selector, you'll grab !important
workaround. plain wrong. it's ugly workaround , not real solution. confuses style rules , more in long term. !important
should only used in order override values hardcoded in html element's style
attribute css stylesheet file on (which in turn bad practice, in rare cases unfortunately unavoidable).
Comments
Post a Comment