I have some html files with their own css. I want to use them in a gwt application so i copied the html and the css files in the application.
The problem is when i open the html it uses the gwt theme style. For example in my css the html 'body' background color is black, but it looks white unless i deactivate the theme.
How could I override the gwt theme style and use my css styles?
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.
Answer: You cannot override inline CSS if it has ! important . It has higher precedence than the style in your external CSS file. , there's no way to override an inline !
Inline styles added to an element (e.g., style="font-weight: bold;" ) always overwrite any normal styles in author stylesheets, and therefore, can be thought of as having the highest specificity.
This post on the GWT mailing list describes an alternative solution. You have to create a new ClientBundle
which references your CSS file:
import com.google.gwt.core.client.GWT; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.CssResource; public interface Resources extends ClientBundle { public static final Resources INSTANCE = GWT.create(Resources.class); @Source("style.css") @CssResource.NotStrict CssResource css(); }
And then inside your onModuleLoad()
method you have to inject the CSS file:
public class YourApp implements EntryPoint { public void onModuleLoad() { //... Resources.INSTANCE.css().ensureInjected(); //... }
In my opinion this is the cleanest and easiest way to override the styles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With