.. when things get ugly?
In my previous posts about Clean Semantics I have explained a bit about my philosophy of Clean Semantics. Trying to get rid of the div tag soup and only use the real semantic markup. Driving it to the extreme (I know) and literally avoiding any tag that has no direct semantic value. Call me a Semantic Fundamentalist.
I have shown markup for a simple layout with a header, a menu and a content area. But I left with a cliff hanger regarding a three column layout.
Three columns: first attempt
My first attempt was using some form of positioning to place the columns left and right. Positioning the top element of both the left and right column was easy: place them just below the header and to the left or right. But I could not really find a way then place the next elements below these first. There is no way of knowing the height of the elements. So I sighed and came up with the old fashioned way: wrap the columns in a <div>
. Sigh! Here's the example of a three column design using only two <div>'s.
As you can see it works. I have placed some different types of elements in there and it behaves all in all like expected. And only two <div>'s! And the content is a nice order. The columns follow after the main content, which is good practice for search engines. But the order can be swapped about, layout stays the same.
But those two <div>'s in there are not semantic. So for a Semantic Fundamentalist, like me, they are two too many. It did not give me the feeling of having achieved anything.
Three columns: second attempt
So I decided that positioning was not the right solution path for the problem and I returned to good old floating.
I mentioned that it would be relatively easy to combine my first example with the menu on the left with my third example with a horizontal menu. Then if I just add some right floated content I would be well on the way.
The sub menu has the same styling as the menu in the first example. The content on the right is just floated to the right and with clear to the right to move the item below the previous one.
float:right;clear:right;
This was indeed not too difficult, see the example.
I may have lost the source order independence, but still I can live with that. I also have a feeling that this could be the right approach.
Three columns: third attempt
In the previous example I have take a small step with floating and clearing to the right. So let's do the to the left as well.
float:left;clear:left;
Sounds just so simple. Why I ever considered positioning I don't know. My first angle of attack is usually floating things into place.
So, the simple floating and clearing left and right could do the trick. Here is what I made of that: three column layout with no <div>
's. Do me a favour and view it using Internet Explorer 6. Yes, you read that correctly. In Internet Explorer 6 this markup and styling works. In Firefox things go a bit awry. To me it seems the floating and clearing rules are interpreted differently. And IE7 does the same thing as Firefox, so maybe the bus is in IE6? Hmmm, too bad.
I have only tested the layout in Firefox and IE6 and IE7 so far, so using a different browser will probably show even more possible outcomes.
But which is right? IE6 or Firefox & IE7?
Remains the question: which browser does it wrong? Or more simple what do the rules state as correct floating behavior?
Let's look up the W3C rules in CSS 2.1.
The W3C's CSS 2.1 definition of floatA float is a box that is shifted to the left or right on the current line. The most interesting characteristic of a float (or "floated" or "floating" box) is that content may flow along its side (or be prohibited from doing so by the 'clear' property).
In the image this rules is visualized. When floating to the right, the elements go all the way to right until they can not move any further, because they reach the right edge of the containing element or they are stopped by another right floated element. When the element is cleared to the right it does not allow for any elements to be on the right, it clears those away or rather takes the easy way out and moves down a bit so that it can snuggle up against the right edge of the containing element.
When I then combine the right float and cleared elements with left float and cleared elements I expect something like the picture below. A neatly stack of elements on the left and right side of my containing element. Just like IE6 shows it. So, in my interpretation Firefox and IE7 have a bug rendering the markup and styling. It is a hard conclusion to draw here, but I think it is true. Looking at how the markup is rendered in Firefox and IE7 I have the feeling that somehow elements that are cleared on the right are also cleared on the left, but not all. The last floated element to the right has no influence on the vertical position on the first left floated element. Multiple floated and cleared elements to one side apparently make Firefox and IE7 only remember the vertical position of the last element. Anyway, this approach is not rendered consistently enough across different browsers to use it. Let's forget it.
What to do?
What can I do now? It seemed to be going so well. Can I still find a workaround for this problem or should I just let it be and stick with using two <div>
's?
I'm not giving up yet. I will give it another try. Meanwhile, if anyone with another browser can tell me if that browsers shows my three column layout with no <div>
's correctly or not, please do. The comments are open.
Update
Now that I have Safari 3 beta for Windows on my machine I see exactly the same appearance as in Firefox. So, taking into account the execllent performance of Safari in the area of standards compliance rendering I think I must take back my conclusion to the bug in Firefox.
The correct rendering of Internet Explorer is just a lucky bug.
This article is part of a series of four
- First steps towards Clean Semantics
- The shape of Clean Semantics
- Clean Semantics: the three column attempt
- Clean Semantics in practice (Will follow shortly).
I like your idea of a pure semantic layout but wonder if your third attempt is a step in the wrong direction. My personal feeling is that adding classes to all those elements ie. class="right" is less semantic then having a wrapper div. You use less markup with the div and also I thought a div is supposed to be used for seperating divisions and areas of a page. Therefore I beleive a two divs are the right choice for the job
ReplyDeleteBen, I think you are right saying that a solution with just a few div's is better and does not completely destroy the semantics.
ReplyDeleteThe entire experiment was to find a way to create a page layout with using any div as they lack any 'real' semantic meaning. Yes, they do act as a division to separate areas of a page, but there's no textual meaning in the way a h1 or p tag has.
On the other hand I do not agree with you that adding class="right" is less semantic than having a wrapper div. I do not think that adding a class atribute (or any other attribute) reduces or improves the semantic value of an element.
Theoretically, I shouldn't have used classes like "right" and "left" but something like "sidebar" or "secondary" but that's pushing it a bit too far.
BTW you should have a look at the link to your site and add the protocol.
Having "right" and "left" classes is clearly non-semantic, but replacing them with "sidebar" and "secondary" is also non-semantic in a way. Thing is that you would probably mark with class only elements that you need to style, and therefore have style-dependent semantical xhtml.
ReplyDeleteTheoretically, if you wish to leave dry semantics in the xhtml, while enabling css to style it any way you like, you'll need to provide some method to select any xhtml element in the css.
This either calls for rigid xhtml structure, very inconvenient for authors and CMSs, or strategically placed ids on xhtml elements.
--
Lupein
Drupal themes - themeartists.com