1 | 2

6 - 7   [7]

The Lost Child Hack

Also relates to CSS Design

Busy month!… Anyway, I made a startling discovery in my experience of CSS earlier today. For, as long as I have been using style sheets, I have always considered the use of the child selector (A>B), as a way to hide declarations from the Internet Exploder family. The Box Model Hack shows a typical use of this selector in the be nice to Opera paradigm. Well, since I started testing designs across the IE browsers using the XP browser set a number of complications have arisen from version 5.0 ignoring the height rule, and frustrating as it is I have not, until now, been able to resolve this.

Firstly let me briefly explain my reasoning for using height. I begin the development process by drawing up an XHTML document for the content of the page. I find doing this before even contemplating the design of the page helps reduce any design bias that might contravene the logical flow of the document. A typical example is the menu (or navigation bar). Web design and usability standards decree that in general the navigation should be placed either at the top of the page or to the left or right. This makes sense and is generally what a client or user expects. However, achieving this with pure CSS (that is without tables) has an immediate impact on the logical flow of the underlying content. To place the navigation at the top, or float it to the left, requires that the menu must precede the content of the page in the document tree. This can work, provided a skip menu link is provided for alternative user agents. But presenting copy first on the page has potential benefits for search engine placement. So I generally place the menu after the content.

Using the position:absolute declaration the menu container can be placed anywhere on the screen, be it in a relatively positioned parent or the document root. But if it is placed for example on the left hand side, a recurring CSS columnar complication arises - if the main body of the page is resized to a smaller font, potentially the menu will break the page design and spill off the bottom of the page. The simple way to avoid this is to use the height declaration to freeze the size of the page. Caution is required, since the browsers interpret the height element differently. In IE, content extending beyond the height of its parent container stretches the container, whereas Mozilla and Opera spill the content out of its parent. The following code avoids this:


#box2 {height:300px;min-height:300px;}
#box1>#box2 {height:auto;}

A minimum-height is read by Mozilla and Co., but then the container's actual height is reset to automatic so it can correctly stretch as needed. Meanwhile IE ignores the automatic height declaration because it does not understand the child selector. Or so I thought!!! I finally discovered that the reason all my perfectly structured and placed designs were breaking in IE 5.0 were because it was understanding the child selector and resetting the height to automatic. But this goes against everything I understood of CSS browser support. Surely the child selector is a feature of the advanced browsers and why on earth does it work in IE 5.0 but not more recent versions of the browser?

Following some testing it boils down to this. The child selector appears to only work in IE 5.0 when the parent and child are both id declarations. This is why it was causing me so much grief in the scenario described above where IDs are used to define the containers for page layout. An immediate advantage of this is yet another hack to resolve differences between IE 5.0 and IE 5.5. I have got quite used to using the version 5 family hack discussed previously complemented the mid pass filter to keep the hacks exclusive of the pure CSS file. Assuming the element and its parent have an id the hack can be simplified to:


child {name:value2;} parentID>childID {name:value1;}

The Lost Child Hack!

On a quick scrub of the web, I discovered that this also exists in another guise. Tom Clancy points out that the same thing occurs when a space is placed either side of the elements (IDs are not required): html > body. I have not had a chance to test this yet.

Posted on Dec 19, 2003 at 02:29:23. [Comments for The Lost Child Hack- 1]

IE5.0 Versus IE5.5

Also relates to Accessibility

I am a strong advocate of accessibility, and make every effort to sell and build website for clients that are conforming to the WCAG, while maintaining Web Standards and page validity. For all the hard work, sometimes those ever so standards-friendly browsers from Micro$oft put a spanner in the works!

On completion of a recent website, with all the usual set of validity and accessibility tests, I was perturbed to hear from the client that the display on screen was total chaos! As it turned out, they had just had MS 2000 Pro installed, accompanied by IE5.0 as the default browser. While I urged them to upgrade their browsers, it was conceivable that a portion of the target audience would also be using IE5.0, and so the pages were not accessible. A few weeks ago, this would have been a real issue with no way for me to test where the problems were arising, but fortunately recent discoveries allow testing over the full range of IE browsers.

So I got to testing, and soon traced down the glitches to a couple of CSS incompatibility issues for IE5.0. The major cause of so much destruction was the use of relative for container positioning, and IE5.0's reluctance to acknowledge the height attributes in these containers. I knew declaring position:relative was a cause for disappearing elements across IE5.x and had formulated personal guidelines for using this declaration, but did not know it could eat appart the display in IE5.0.

Most CSS hacks for hiding code seem to classify IE5.x as a single entity, but in this case I needed to write different code for IE5.0 and IE5.5, otherwise one of them would fail to display correctly. The best solution I found in the archives is the following snippet:


div#id {
  position: static;               [1]
  position/* */:/**/:relative;    [2]
  position:relative;              [3]
}

  1. Line [1] is read by all browsers - final value for IE5.0
  2. Line [2] is ignored by IE5.0 and IE5.5 but read by all other browsers
  3. Line [3] is also ignored by IE5.0 but is read by IE5.5 - final value for IE5.5

It is a great shame when so much work is put into accessibility for all browser mediums and users, yet making a site accessible for the client rests on a bunch of ugly hacks! I suppose a better long term solution to this would be to separate this bunch of IE CSS hacks using Tantek's Mid Pass Filter. Then, once these legacy browsers have finally been put down, the hacked files could just be discarded.

Posted on Nov 18, 2003 at 18:03:00. [Comments for IE5.0 Versus IE5.5- 0]

Breadcrumbs Trail

[ Home ] -> TW Blog -> Exploder
Site Map

The Severn Solutions website achieves the following standards:

[ XHTML 1.0 ] [ CSS 2 ] [ WAI AA ] [ Bobby AA ]

Page compiled in 0.085 seconds