<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>kuwamoto.org &#187; css</title>
	<atom:link href="http://kuwamoto.org/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://kuwamoto.org</link>
	<description>various stuff, mostly boring</description>
	<lastBuildDate>Sun, 18 Mar 2012 00:16:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CSS is too hard</title>
		<link>http://kuwamoto.org/2006/04/26/css-is-too-hard/</link>
		<comments>http://kuwamoto.org/2006/04/26/css-is-too-hard/#comments</comments>
		<pubDate>Wed, 26 Apr 2006 22:28:06 +0000</pubDate>
		<dc:creator>sho</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[webdesign]]></category>
		<category><![CDATA[webstandards]]></category>

		<guid isPermaLink="false">http://kuwamoto.org/2006/04/26/css-is-too-hard/</guid>
		<description><![CDATA[I used to think of myself as knowing a lot about CSS. For starters, I&#8217;d been responsible for the CSS implementation in Dreamweaver. I was also a member of the W3C CSS working group. I wasn&#8217;t a major contributor (I didn&#8217;t author any of the chapters of the spec, for example), but I thought I [...]]]></description>
			<content:encoded><![CDATA[<p>I used to think of myself as knowing a lot about CSS. For starters, I&#8217;d been responsible for the CSS implementation in Dreamweaver. I was also a member of the W3C CSS working group. I wasn&#8217;t a major contributor (I didn&#8217;t author any of the chapters of the spec, for example), but I thought I knew the spec pretty well.</p>
<p>It&#8217;s been a while since I&#8217;ve touched CSS, and in coming up with the design for this blog, I was reminded again how difficult it is to use CSS to get the layout you want. It was <em>incredibly</em> difficult. I couldn&#8217;t get it to work and I ended up having to google around to figure out how other people had done their page layouts.</p>
<p>Does it have to be this way? Shouldn&#8217;t a reasonably smart person who has read the spec be able to create a layout without referring to a guru?</p>
<p><span id="more-60"></span></p>
<h2 class="separator">~</h2>
<h3>Tables vs CSS</h3>
<p>The general idea of using CSS for layout is absolutely right. CSS lets you separate presentation from content, which is a good thing. The general idea of using tables for layout is wrong for exactly the same reason. It intermixes content with presentation, and besides, tables were originally meant to represent tabular data. There is another, more subtle reason why CSS is better than tables for layout: accessibility. With CSS, you can order your content in the preferred order for screen readers, and then use CSS to dictate where everything should go. With tables, the layout dictates document order.</p>
<p>However, there are some things that are trivial to do with tables that are mind-bendingly difficult with CSS. A lot of it has to do with what I&#8217;ll call float abuse.</p>
<h3>Float abuse</h3>
<p>There are a number of ways that people have found to create two and three column layouts that are popular on the web. Most of them rely on <code>display: float</code>.</p>
<p>Floats were originally intended to be used for floating elements such as sidebars.<span class="leftquote">This is an example of a traditional use of float.</span>They were not specifically designed to handle the overall layout of a page. Using floats to handle the overall layout of a page is not quite as egregious as table abuse, but there are similarities.</p>
<p>One of the problems with using floats to do overall layout is that they have significantly different rules for how margins are handled when compared with inline or block elements. If you were designing a system from scratch to define web layouts, would you purposefully make it so that the left column had different rules for margin handling than the right column? Probably not. Yet that&#8217;s what you get with floats.</p>
<p>The reason that margins need to be treated differently for floats is clear when you consider the original use case. Here&#8217;s a diagram from the CSS2 spec:</p>
<div class="figure">
<a href="http://www.w3.org/TR/REC-CSS2/visuren.html#floats"><img alt="diagram showing how margins work with floats" src="http://www.w3.org/TR/REC-CSS2/images/floateg.gif"></a></div>
<p>However, when you use floats to do a multi column layout, look at what happens to the margins. Let&#8217;s assume that A, B and C each have a top and bottom margin of 10px. Let&#8217;s also assume that B is floated left. In this case, the margins of A and C collapse, but the margin of B does not.</p>
<div class="figure"><img alt="diagram showing how margins get weird with floats" src="http://examples.kuwamoto.org/CSS/float.png"></div>
<p>Worse yet, some of the wrapping rules of floats can lead to situations like this:</p>
<div class="figure"><img alt="diagram showing how margins get weird with floats" src="http://examples.kuwamoto.org/CSS/float2.png"></div>
<p>As bad as tables are, you rarely get yourself into situations like this with tables. My belief is that all these problems occur because floats were never designed to serve this purpose in the first place.</p>
<h3>How should it work?</h3>
<p>Bert Bos once mentioned to me that the CSS group had discussed doing something within CSS to handle overall layout. I don&#8217;t know what the syntax was that was being thrown around at the time, but it looks like there has been some <a href="http://www.w3.org/TR/2005/WD-css3-layout-20051215/">progress on that front in the CSS3 spec</a>. The current proposal seems a bit bizarre to me, but I am incredibly happy that they are looking at this issue. FWIW, my personal preference would be to introduce @ rules to do a container based layout hierarchy:</p>
<pre>@layout {
    name: "threecol";
    type: vertical;
    width: 100%;
    height: 100%;
    children:
        @layout {
            name: "headerArea";
            width: 100%;
            height: 40px;
        },
        @layout {
            type: horizontal;
            width: 100%;
            height: 100%;
            children:
                @layout {
                    name: "leftArea";
                    width: 150px;
                    height: 100%;
                },
                @layout {
                    name: "mainArea";
                    width: 100%;
                    height: 100%;
                }
        }
}

#header {
    layout: "headerArea";
}

#sidebar {
    layout: "leftArea";
}

#content {
    layout: "mainArea";
}
</pre>
<p>I&#8217;m sure that the above psuedo-CSS has lots of problems, but the general gist is that I want to think about layout in terms of containment, not in terms of slots. But in any event, anything is better than thinking about floats!!</p>
<h3>When to be practical, and when not to be</h3>
<p>The main thing standing in the way of a new, better syntax for page layout is the real world. Can the W3C create a proposal that a whole consortium of companies agree to? Can we get this implemented in the browsers?</p>
<p>These are good questions, and for the foreseeable future, we may have to live with what CSS2 offers us. However, I want to make sure that pragmatism doesn&#8217;t lead to complacency. Is it great that I can now do a web page layout using standards-based CSS? Absolutely. Does CSS seem easy enough for the kinds of things that people want to do with it? Absolutely not! Laying out a web page in CSS is mind-bendingly hard. It shouldn&#8217;t be that way. People who create web pages should be jumping up and down asking for something better.<br />
]]></content:encoded>
			<wfw:commentRss>http://kuwamoto.org/2006/04/26/css-is-too-hard/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

