Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override default CSS in modern GWT applications?

From the following page: Developer's Guide - CSS Style

it is made clear that in modern GWT apps there's two ways to declare css styles:

Using a CssResource contained within a ClientBundle. Using an inline element in a UiBinder template.

How do you use either of these two methods to override the GWT default styles such as gwt-Button, gwt-TextBox etc?

I know it's still possible to use a css style sheet that you reference from either the html page or the .gwt.xml file. However, I'd like to avoid this since these methods are now deprecated.

like image 556
Fred Avatar asked Nov 18 '11 13:11

Fred


People also ask

How do I override a CSS code?

To override the CSS properties of a class using another class, we can use the ! important directive. In CSS, ! important means “this is important”, and the property:value pair that has this directive is always applied even if the other element has higher specificity.

What is CSS rules overriding?

CSS allows you to apply styles to web pages. More importantly, CSS enables you to do this independent of the HTML that makes up each web page. Overriding: Overriding in CSS means that you are providing any style property to an element for which you have already provided a style.


1 Answers

Use an @external @-rule to disable obfuscation for the given CSS class names: http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#External_and_legacy_scopes You can, for instance, put the following in any CssResource stylesheet:

@external .gwt-*;

But IMO, the best practice is to instead addStyleName or setStyleName (or in UiBinder addStyleNames="…" or styleName="…" respectively) on widgets. And if you want to customize a theme, copy it first as your own theme and tweak your own copy (rather than overriding styles using the CSS cascade). As an added benefit, you'll have lighter stylesheets, so they'll be faster to download for your users, and “faster is better”.

As a side note, UiBinder generates an implicit ClientBundle, where each <ui:style> element generates an implicit CssResource (and automatically calls ensureInjected() on it); so there's no much difference between <ui:style> and a CssResource.

like image 85
Thomas Broyer Avatar answered Oct 01 '22 16:10

Thomas Broyer