Blog Archives

January 8th, 2010
5:35 pm
ICEfaces ice:form tag adds extra auto margin in IE7

Posted under JSF
Tags , , , ,

The ice:form tag renders a stateSavingMarker div which declares a couple of hidden fields for use by ICEfaces.

In IE7, (or IE8 in IE& compatibility mode), this div has its margin to auto which can cause an extra 10px or so margin to be added in between any elements outside the form and those inside.

This can be eliminated by adding a style to the form, either by adding a StyleClass attribute to refer to a CSS class, or by using the Style attribute to code an inline style. As this is a ‘one off’ just to clear a margin, the following example uses an inline style :-

<ice:form style=”margin:0″>

No Comments »

January 8th, 2010
9:19 am
Quirks mode & DOCTYPE switching issues with IE

Posted under HTML
Tags , , , ,

The perceived wisdom is that adding a valid DOCTYPE switches a browser from quirks mode into standards mode, but the truth is that it depends on the DOCTYPE and the browser, and also can depend on how the browser validates the page against that DOCTYPE – the browser can potentially change its mind part way through parsing a page.

I was coding an html page which had the following DOCTYPE (which was auto generated by Topstyle 4), and which still threw IE8 into quirks mode :-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

The following DOCTYPE corrected the problem and put IE8 into standards mode :-

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

When using Facelets which is xhtml based, as detailed in this post here re ICEfaces, the actual DOCTYPE outputted by ICEfaces is as follows – this also works well when using standards mode with xhtml/facelets :-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I found the following sites useful when looking for information on this:-

Note re the last link – a Bookmarklet is a link containing javascript which performs some action directly in the current page. I linked to the site article as a courtesy, and the site contains a number of other useful Bookmarklets. The actual bookmarklet (link) which will display the browser mode is here. Just copy and paste the link into your address bar.

No Comments »

January 7th, 2010
7:28 pm
Styling tables with CSS

Posted under CSS
Tags , , ,

Rather than use the border keyword in HTML, it is better to style tables in CSS as this localises all the styling in the style sheet and promotes automatic re-use across different tables.

This page from Somacon is an easy-to-use ‘what if’ tool for tweaking all the properties for tables and instantly seeing the effect.

The w3schools reference page for tables may be found here.

This page also from w3schools describes the use of the border-collapse property, which causes the border-spacing and empty-cells properties to be ignored, and for all borders to be collapsed to a single border. This is very useful when you want complete control yourself and to prevent some of these other properties getting in the way, for example when you want a minimal flat solid border.

Note that as is often the case, incorrect HTML can give rise to strange behaviour. For example if you mistakenly set colspan to greater than the number of columns (as I did when I subsequently deleted a column after creating a table and forgot to reduce colspan) you may get a partial double border effect on the right hand side.

Here is an example page with a table illustrating these points, together with all its CSS and HTML.

No Comments »

January 7th, 2010
5:45 pm
Using Fonts in CSS

Posted under CSS
Tags , ,

The following articles are helpful re correct choice of font, and how to size and use the various units correctly.
Issues such as providing sensible fallbacks in the font list to cater for different browsers are covered, together with the use of the various absolute and relative sizing units, and how fonts are inherited

http://www.w3schools.com/css/css_websafe_fonts.asp

http://www.w3schools.com/css/css_font.asp

Gernally accepted advice is as follows :-

  1. Define a default family in CSS for the body tag, consisting of a suitable fallback stack. Use a sans serif for screen use as it is more readable
  2. Define a default size using percent in the body tag, then use ems after that for relative sizing. This gets around some browser quirks with IE, and allows resizing by the user for all browser types.
  3. The default will be inherited throughout the document. However I have found issues when tweaking local CSS files during testing – sometimes old values ‘stick’ perhaps due to caching effects.
  4. There is an issue apparently with some older browsers that tables do not inherit a default body font. Therefore, the default should be specified for body, table as in the example below.
  5. Note that not all fonts in the stack (such as the basic fallback sans-serif) are necessarily scalable, so size changes may not appear to work if an inferior fallback font is picked up.

The following is an example stack in css :-

body, table {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 100%;
    color: #000000;
}

No Comments »

January 7th, 2010
5:14 pm
Hover and other effects in CSS using Pseudo Classes

Posted under CSS
Tags , , ,

There are plenty of sites about showing how to do hover and click (=active) effects on an element (typically a link or image/image button) using Javascript, but with modern browsers (including IE7 and above but not IE6) this is completely unnecessary as it can be done entirely with CSS. The advantages are clear – no Javascript is needed, the CSS is straightforward, and no round trip to the server is needed. The typical effects used are to swap images or highlight using a different border or background.

These effects can now be performed on any element, not just a link, but check out compatibility as IE has had some issues with this. I have performed this on image buttons as well as links and had no trouble.

The W3schools article on Pseudo Classes is here. An example of using the hover effect to switch a background image via CSS may be found here. (Note the importance of setting an explicit width and height in the CSS – required because the example uses background images).

The pseudo class can be added to an existing style class. The following simple example shows an ICEfaces Image button with a style class, with modified pseudo classes used in the CSS to highlight the border differently on hover and active (active in CSS terms means click).

CSS

.ImageButton {
	margin: 1px;
	padding: 1px;
}
.ImageButton:hover {
	padding: 0px;
	border: 1px solid #ffa600;
}
.ImageButton:active {
	padding: 0px;
	border: 1px solid #ffd800;
}

JSF

<ice:commandButton image="images/arrow-up.gif"
                   styleClass="ImageButton">
</ice:commandButton>

No Comments »

January 7th, 2010
1:14 pm
Editing HTML and CSS – TopStyle

Posted under CSS
Tags , , ,

Topstyle Pro is my preferred editor for HTML and CSS. It is primarily billed as a CSS editer and  previewer, but has evolved into an equally powerful HTML editor. It has dynamic in-window previewing of changes, which is especially useful when tweaking tricky CSS, and has intelligent code/tag completion, error detection/correction/validation plus a large number of other powerful features. I find it especially useful as, not being a CSS expert who uses it all the time, the code completion, error detection/correction and dynamic preview help to fill in the missing/forgotten knowledge gaps.

No Comments »

January 7th, 2010
11:55 am
Using Unicode Characters in HTML

Posted under HTML
Tags , ,

Numeric Unicode references can be added using the format :-

  • &#N; (for decimal unicode value N)
  • &#xN; (for hexadecimal unicode value N)

The use of Webdings and Wingdings font families is not universally compatible and is considered a hack – use unicode characters instead as above.
Wikipedia has a good article on this here.
Full unicode character charts may be found on unicode.org here.

No Comments »

January 7th, 2010
10:38 am
Using Floats in CSS

Posted under CSS
Tags , , , ,

The following sites give a good introduction and insight into the use of floats and some of their quirks for the unwary.

This Excellent introductory float tutorial from Max Design is well worth working through entirely as a starter for beginners.

This article from CSS Newbie details some of the quirks of floats and how content flows around floated elements, and how container height is affected. There is a fundamental point which the article illustrates, but which I could not find spelled out clearly and obviously in other articles anywhere. When other elements flow around a floated one, it is the content area of their CSS boxes which flow. It is therefore perfectly possible (and normal) for the floated element to end up sitting inside the margin, border and padding areas of the elements which float around it. The article also describes how the floated element can overlap (extend beyond) the border of the flowing  element if for example the floated element is longer. This is not what you might expect. However, when the flowing element is itself floating, then the height of the (inner) floating element dictates the height of the flowing element.

The ‘flowing of content area’ behaviour is used when designing multi column layouts, as this article from Comunity MX illustrates. For example in a 2 column layout, the left column content is placed in a ‘float: left’ div. The adjacent right colum flows around it, and has a left margin set to the width of the left column plus any desired gap.

This article by Matthew James Taylor describes a template for a 3 column floating layout with header and footer. The interesting thing about this is that Matthew does not use any CSS hacks or browser specific coding, but manages to achieve wide cross browser compatibility. He also has a number of other templates, all freely available, an addition to an interesting article on how to acheive equal height column backgrounds, again by nesting floating column divs inside other divs which are also floating.

No Comments »