GWT theme style overrides my css style - css

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?

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.

Like Sarfaz said - !important should be your last resort as it kind of defeats the whole concept of Cascading Style Sheets.
Anyway, in GWT, in order to easily override the core GWT styles contained in the theme you selected, you should locate your module file (the one that has a file name ending on *.gwt.xml), then locate the line where you declare your theme and put your custom/whatever stylesheet after it, like this:
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<stylesheet src="CustomStylesheet.css" />
Note, however, that for GWT 2.0 CssResource and UiBinder is recommended.
Be sure to read the appropriate section of the docs for more pointers.

You can override the styles of GWT by using the keyword !important in all your css of the html files, for example, if one of your html file contains this css:
background-color:#000000;
Then you should write it like this:
background-color:#000000 !important;
Do the same for all your styles in html files.
Note that using !important is not the best way, if you can find any better alternatives you should go for them first.

In addition to using !important you can also rely on CSS Selector Specificity.
Most (all?) of the GWT styles are stated using just class eg:
.gwt-DisclosurePanel .header {
color: black;
cursor: pointer;
text-decoration: none;
}
To override this you can use !important or you can be more specific in your selectors eg:
table.gwt-DisclosurePanel .header {
text-decoration: underline;
}
How does this work? This works because adding the element name (table) to the class in the selector makes it more specific than just the class alone. This will override other styles even from stylesheets listed lower in the header.
Giving your widgets IDs and using those is even more specific.

I know it's not very elegant but I found it rather effective to replace the standard.css file in the output files generated by GWT with an empty file.
(Maven can take care of that reliably.)

The solution <stylesheet src="CustomStylesheet.css" /> is deprecated and did not work with the new superdevmode.
A solution that worked for me (using GWT 2.7) was to create a new custom theme:
projectPackage/themes/MyCustomTheme/MyCustomTheme.gwt.xml
<module>
<stylesheet src="gwt/MyCustomTheme/MyCss.css"/>
</module>
projectPackage/themes/MyCustomTheme/MyCustomThemeRessources.gwt.xml
</module>
projectPackage/themes/MyCustomTheme/public/gwt/MyCustomTheme/MyCss.css
(Note: removing the gwt/MyCustomTheme/ part of the path worked in devmode but didn't work in deployed version, of cause you can still rename 'MyCustomTheme' to something of your liking)
The css file you want to use
Project.gwt.xml
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.0//EN"
"http://google-web-toolkit.googlecode.com/svn/releases/2.0/distro-source/core/src/gwt-module.dtd">
<module rename-to="Project">
(...)
<!-- Inherit GWT theme. e.g. the Clean theme -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- Our custom theme -->
<inherits name='projectPackage.themes.MyCustomTheme.MyCustomTheme'/>
(...)
</module>
Note: You can get a sample custom theme using http://gwt-theme-generator.appspot.com/ and extracting the downloaded .jar file.

That's easy. Just put your CSS link under the GWT's module script:
<script type="text/javascript" src="myapp/myapp.nocache.js"></script>
<link rel="stylesheet" href="myapp.css" type="text/css">

Related

SilverStripe CMS custom css

When you set an extra css class to a CMSField by ->addExtraClass("my-class");, which css file can you edit to set the styling for this new css class?
The only way I see now is by editing either css files in the Framework or CMS folder, something I rather avoid doing.
Is it possible to include a link to a custom css stylesheet in the CMS area where I can place all the css code?
You can load your custom Stylesheet into the CMS by adding the following to your config.yml file:
LeftAndMain:
extra_requirements_css:
- mysite/css/mystyle.css
you can add code like this...
Requirements::customCSS('
#Form_FilterForm .field {
display:inline-block;
width:31%
}
');
...almost anywhere and it will be included.
If these must be in the head tag then...
Requirements::insertHeadTags("
<style>
#Form_FilterForm .field {
display:inline-block;
width:31%
}
</style>
");

How to override Bootstrap styles in Meteor?

I'm using twbs bootstrap 3.3.6 with Meteor and trying to style a <fieldset>.
However when I use the Chrome inspector it says that the style is coming from bootstrap.css even though I have tried using class-specific and id-specific css.
My style sheet is in the application root, as suggested by some answers.
I'm very new to meteor and css so I could be making a novice error.
Otherwise, what's the best practice to override bootstrap css settings?
Generally if you want to override the css you should put your css file after all of the other files like the bootstrap css because css starts from top to bottom so the bottom lines are the ones that will be executed, example:
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/your-css.css" />
Also you can add !important at the end of every css line to give that style the top priority no matter of the line index, example:
.someclass {
color: red!important;
}
You can either override the specific property on the same class in your css...
.btn {
background-color: #fff !important;
}
...create an inheritance map so that it only applies to the element inside another specific element...
div.classForSpecificContainer btn {
background-color: #fff !important;
}
or specify your own class and add it to the element in question
myOverrideClass {
background-color: #fff !important;
}
The.. important part is that you use !important; to prevent Bootstrap from overriding it. That will generally solve the problem even if the CSS files load in the incorrect order, but not always. I have made a habit of prefixing my CSS files in the same folder with z- to make sure they get loaded last if I'm using something like Meteor that merges and compresses the CSS.
This seems to be a common problem in Meteor because of the way their build injects the merged stylesheet into the top of the html <header> instead of the bottom. There is a merged PR that looks like it will be available in 1.6.2 that allows you to put a pseudo tag anywhere in the <head> you want the merged css injected.
Example: proposed availability in 1.6.2 - PR already merged
<head>
<link rel='stylesheet' type='text/css' href='some-cdn.bootstrap.css'/>
<meteor-bundled-css/>
</head>
That will work once the merged PR is included in the next build.
Until then...
SOLUTION 1: If you're using the bootstrap LESS or SCSS files, you can just import it into your client/main.less or client/main.scss file and then import your override file after this. It looks like you're using pre=compiled css though, so move to SOLUTION 3.
SOLUTION 2: Use !important on the end of your lines... BAD not recommended practice. If you use important you break the cascade.
SOLUTION 3: Put you third-party library overrides files in your public folder and manually <link> it below the bootstrap <link> in your head. I suggest this for now.

How can I load a CSS file in my NativeWindow?

I have a Flex application with a main class that is a WindowedApplication. The CSS file is loaded using the <fx:Style source="defaults.css"> tag in the MXML.
However, when this main class will open a NativeWindow, the CSS does not get applied. I have a subclass of NativeWindow where I can add some things, but this is ActionScript, not MXML. Is there an equivalent of <fx:Style/> for AS? Or do I have to do things in a different way?
UPDATE:
None of the proposed solutions so far seem to be working. I will try to write a small test app to show the behaviour, maybe it is a bug in the Flex framework.
I think you'll need to load the styles via a compiled stylesheet (as a SWF). You can compile a stylesheet to a SWF with MXMLC (mxmlc stylesheet.css). Then use StyleManager.loadStyleDeclarations(swf) to load and apply the styles.
You might have to do all styling with
someComponent.setStyle("someProperty", "someValue");
There's also a [StyleSheet](You can use StyleSheets parseCSS method class that you could use but it only applies to TextField elements IIRC
Have you tried using global selectors in your CSS?
like
global {
color: #000000;
}
or
s|Button
{
color: #FFFFFF;
skinClass:ClassReference("com.what.skins.ButtonSkin");
}
I have these things in my main application file in a style block and they are applied to all views

garbled css name when styling within UiBinder

For my GWT application, I want to show the selected row in a FlexTable, and for that purpose I add a style to the specific row:
#UiField FlexTable productTable;
int row;
[...]
/* select row */
productTable.getRowFormatter().addStyleName(row, "row-selected");
In the corresponding ui.xml file, I have the style added as follows:
ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:u="urn:import:myapplication.client.ui">
<ui:style>
tr.row-selected {
background: #92C1F0;
}
</ui:style>
<g:VerticalPanel>
<g:ScrollPanel>
<g:FlexTable ui:field="productTable" width="100%" height="100%">
</g:FlexTable>
</g:ScrollPanel>
</g:VerticalPanel>
</ui:UiBinder>
This does not work, while adding the style in my global .css file does. In FireBug I see that the name tr.row-selected is garbled into something like: tr.GB1HWLGEI
Why does this not work and how should it work instead?
UiBinder uses ClientBundle for ui:style, so the rules and syntax/features of CssResource apply.
This means that your CSS class names will be obfuscated (so that they're unique and won't conflict with a same-named CSS class from another CssResource or external stylesheet).
In your case, you can either define a CssResource interface and declare the ui:style to extend that interface and inject the instance into a #UiField; so you can use the obfuscated style into your addStyleName; as in http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html#Programmatic_access
Or you can use #external in your ui:style to disable obfuscation for the CSS class; see http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#External_and_legacy_scopes.
Garbled is really obfuscated which will be faster in the browser and harder for someone to reverse engineer. It also means you don't need to worry about css namespace conflicts.
So, just use the following line in your ModuleName.gwt.xml file during development to disable obfuscation.
<set-configuration-property name="CssResource.style" value="pretty" />

GWT StackPanel Styling

I guess this should be straight forward, except I just can't figure it out. I'm trying to use a stackpanel. I'm trying to style it so that the header's text, background color, etc matches the rest of my app.
I'm using css and a client bundle to apply styles to my components.
I've tried to style the stackpanel using two methods and both have failed.
Method1:
If I apply the following to the MyProject.html style section:
.gwt-StackPanel .gwt-StackPanelItem {
font-weight: normal;
font-size: 8pt;
width: 100%;
background: green;
}
.gwt-StackPanel .gwt-StackPanelItem-selected {
background-color: red;
}
And then load it in firefox, I still see the default styling. If I open up firebug and inspect the element, I see that the gwt default styles are still being applied.
Method 2:
If I encapsulate the above styles in my css file then GWT compiler complains about obfuscated styles? So I added the #external attrib to the styles, the compiler doesn't complain, but I still don't see my changes applied.
Thanks in advance!
I know this is a late answer, but in case someone comes here later I have a suggestion. The reason your CSS gets overridden by the gwt theme is that the gwt theme is taking precident in your module file (.gwt.xml). The way to change this is to include your own CSS file in your module file after the gwt theme.
For example, you should see something like this in your module file:
<!-- You can change the theme of your GWT application by -->
<!-- uncommenting any one of the following lines. -->
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<inherits name='com.google.gwt.user.theme.clean.Clean' />
Somewhere after this, add a stylesheet statement for you own css file:
<!-- CSS Style Sheet includes -->
<stylesheet src="<pathToYourCSSFile>.css" />
Now, because your file is included after the gwt style, your styles will take precedent over gwt!
I always comment out this line from the xml file of the module:
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
then you can use your own styles adding stylenames to widgets (stackPanel.setStyle...)
And if you need a default style of gwt you can copy it from gwt-user.jar com.google.gwt.user.theme.standard.Standard.public.gwt.standard.standard.css to your own css file.

Resources