We have started to implement a new Vaadin web app which heavily uses the CssLayout. Mainly to give our designer more freedom and possibilities to include very brand-specific behaviour.
I was recently asked whether it’s possible to have IE-specific CSS files. I’m not a front end developer myself, but it seems common to have CSS that works with IE and other CSS for other browsers.
Looking through the Vaadin code, I found the BrowserInfo class and in particular:
static {
// Add browser dependent v-* classnames to body to help css hacks
String browserClassnames = get().getCSSClass();
RootPanel.get().addStyleName(browserClassnames);
}
and
public String getCSSClass()
Also, the reindeer theme contains a button-ie.css file with .ie classes defined. Without having spent any time trying that out, I want to ask if that’s enough? Creating a styles-ie.css file with .ie styles to get that to load in IE.
I somehow have a suspicion that this would be too nice to be true…
Hopefully Jouni, the Vaadin CSS Ninja, will point out any errors in the following, but basically :
Vaadin doesn’t do selective inclusion of CSS files; it just includes VAADIN/themes/the-theme-name/styles.css.
To allow for browser specific workarounds, it adds CSS classes to the body element of the HTML. Here are some examples from browsers and machines I have on my desk :
As a silly example, if you wanted the background of textfields to be yellow on IE, but green on Safari on mac you could do :[code]
.v-ie .v-textfield {
background: yellow;
}
.v-sa.v-mac .v-textfield {
background: green;
}
[/code]
You can, if you want “silo” the ie-specifics into a separate stylesheet, and include it into the main stylesheet e.g.
in styles.css, you can add @import url(‘styles-ie.css’). This would not be conditional, of course, it would always be included.
If you really wanted to do selective inclusion of a stylesheet just for IE - and I contend that it’s really not necessary - you can do
traditional" conditional stylesheets by overriding ApplicationServlet#writeAjaxPageHtmlHeader(BufferedWriter, String, String, HttpServletRequest) e.g.
That’s exactly what we needed. We’ll keep everything in styles.css and think of splitting it out in different files later if the one styles.css file should be come too big (although probably not anytime soon ;-)).