Wednesday, September 9, 2009

HtML UI Standardization and CSS override

It is important in large applications to standardize HTML elements styling in order to avoid UI inconsistencies. More importantly, standardizing styling of HTML tags reduces the need for using CSS (Cascading Style Sheets) for each HTML element separately, which mean less overhead and less time to initial page load.
Here is how it works:


1. Create a HtmlUtil.java class:

    public static String h1(String text)
    {
return "<h1 class='h1'>" + text + "";
    }
2. Create main.css:
h1,.h1 {
font-sizex-large;
font-weightbold;
padding4px;
margin4px;
}
h2,.h2 {
font-sizelarge;
colorgray;
padding4px;
margin5px;
}
...
3. Use HTML tag to override any CSS styling:
HTML panel = new HTML(HtmlUtil.h3("your text here..."));
Note that functions have HTML tag name as well as a CSS function name, in which you can use the latter to style Element like lable, VerticalPanel, etc.