"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Override GWT Theme Styles with Custom CSS This title is a clear and concise question that accurately reflects the content of your article.

How to Override GWT Theme Styles with Custom CSS This title is a clear and concise question that accurately reflects the content of your article.

Published on 2024-11-20
Browse:905

How to Override GWT Theme Styles with Custom CSS

This title is a clear and concise question that accurately reflects the content of your article.

How to Override GWT Theme Styles with Custom CSS

When integrating HTML and CSS files into a GWT application, users may encounter an issue where GWT theme styles override their custom styles. This can lead to discrepancies in visual appearance, such as a white background instead of a black one.

To address this issue and ensure that your custom CSS styles take precedence, it is recommended to create a ClientBundle that 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();
}

Within your onModuleLoad() method, inject the CSS file using the following code:

public class YourApp implements EntryPoint {

    public void onModuleLoad() {
        //...
        Resources.INSTANCE.css().ensureInjected(); 
        //...
    }
}

By implementing this approach, you can effectively override the GWT theme styles and ensure that your custom CSS styles are applied, giving you greater control over the visual appearance of your application.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3