{"id":253,"date":"2004-11-08T00:00:33","date_gmt":"2004-11-08T05:00:33","guid":{"rendered":"https:\/\/www.goer.org\/wordpress\/when_all_else_fails_read_the_directions"},"modified":"2004-11-08T00:00:33","modified_gmt":"2004-11-08T05:00:33","slug":"when_all_else_fails_read_the_directions","status":"publish","type":"post","link":"https:\/\/www.goer.org\/Journal\/2004\/11\/when_all_else_fails_read_the_directions.html","title":{"rendered":"When All Else Fails, Read The Directions"},"content":{"rendered":"<p>A recent <a href=\"http:\/\/www.mozillazine.org\/talkback.html?article=5490\" title=\"David Coursey Likes Firefox, John Carroll Doesn't Get It\">mozillaZine<\/a> article reports that John Carroll of ZDNet <a href=\"http:\/\/news.zdnet.com\/2100-9588_22-5438955.html\" title=\"Actually, John, Firefox DID get me a date with Carmen Electra\">has issues with Firefox&#8217;s HTML rendering<\/a> when compared to Internet Explorer. Specifically, he has set up <a href=\"http:\/\/www.turtlenecksoftware.com\/bah-humbug.htm\">a test page<\/a> that uses the <code>overflow<\/code> property: Internet Explorer displays the page as Carroll intended, while Firefox and Safari don&#8217;t. As Carroll describes it,<\/p>\n<blockquote>\n<p>&#8220;I have created a Web page with a fixed position left, top and bottom sidebar that surrounds a scrollable area. All regions resize to completely fill the browser when its dimensions are changed.<\/p>\n<p>To make this work, I have a table which lays out the basic position of the main sections (left bar, top bar, bottom bar, content). I&rsquo;ve placed a div tag inside the &#8220;content&#8221; area of the table, setting its width and height to 100% and adding automatic scrollbars by setting the &#8220;overflow&#8221; CSS attribute to &#8220;auto.&#8221;<\/p>\n<p>None of this is rocket science. Some might object to the use of tables, which in CSS circles might seem SO 1990s. I couldn&rsquo;t care less. Tables are easy to use, are immediately intuitive to this old HTML hand-coder, and most important, have existed since the early days of HTML. Regardless of your preferences, there is no reason they SHOULDN&rsquo;T work.<\/p>\n<p>In IE, the page renders properly. In Firefox, the div tag refuses to size relative to its parent table (and doesn&rsquo;t provide scrollbars), which causes the bottom toolbar to disappear past the edge of the screen.&#8221;<\/p>\n<\/blockquote>\n<p>Carroll then proceeds to take Firefox to task for not doing a better job of mimicking IE&#8217;s behavior, implementing its proprietary features, and so on.  The mozillaZine article retorts that it is <em>Firefox<\/em> that is rendering the page correctly, and closes with, &#8220;We&#8217;re not sure if Carroll intends to suggest that Firefox should not only support Microsoft&#8217;s proprietary extensions but also <em>do the wrong thing<\/em> [emphasis theirs] when IE is incorrect.&#8221;<\/p>\n<p>I was curious when mozillaZine claimed that Firefox&#8217;s rendering was in fact correct. Were they right about that? Carroll&#8217;s page is a confusing beast, a weird hybrid of old-skool markup with a sprinkling of advanced CSS layout and overflow rules. Lots of bizarre behaviors we could be bumping into.  Fortunately, it turns out the issue is pretty simple.<\/p>\n<p>Let&#8217;s begin by eliminating a couple of red herrings. First: Carroll&#8217;s impassioned defense of table-based layout is charming, but irrelevant. At first I thought his table structure mattered, but it turns out we can reproduce the effect with only one box element. For its part, the mozillaZine article also snarked that the page &#8220;barely validates as the laxest form of HTML 4.0.&#8221; Barely validates&#8230; like being barely pregnant?  Anyway, it turns out that the validation issue is also irrelevant. We could easily construct an XHTML 1.1 + MathML page that exhibits the same problem.<\/p>\n<p>The root problem is in Carroll&#8217;s usage of the <code>overflow<\/code> declaration. What does <code>overflow<\/code> do? Consider a box that you have  constrained to be, say, 50 pixels by 50 pixels.  Now let&#8217;s say you want the box to contain a long chunk of content, say, all of Deuteronomy. Unless you find a <em>reeeally<\/em> small font, your content will not fit in the box.  That&#8217;s where overflow comes in. The <code>overflow<\/code> CSS declaration defines whether the box should create scrollbars, clip the text, or whatever.<\/p>\n<p>Now consider what Carroll&#8217;s page does. He <em>wants<\/em> to simulate a typical framed layout, where you have a fixed sidebar, topbar, and footer, and a scrollable content pane. So he&#8217;s done the following:<\/p>\n<ol>\n<li>Set <code>overflow: auto<\/code> on his scrollable section. This, he thinks, should cause scrollbars to appear for this section if the content overflows.<\/li>\n<li>Set <code>overflow: hidden<\/code> on the <code>BODY<\/code> element. This, he thinks, should force all other sections NOT to have scrollbars on an overflow.<\/li>\n<\/ol>\n<p>Except there are two problems.<\/p>\n<p>First, Carroll has set the height and width of his scrollable section to &#8220;100%&#8221; instead of a fixed size. This means that the box automatically expands as large as it needs to be to contain its content. Therefore Carroll&#8217;s scrollable section always is large enough to contain all of its content; therefore overflow never kicks in; therefore the section never generates the desired scrollbars, no matter how much &#8220;Bah Humbug&#8221; text Carroll adds.<\/p>\n<p>Second, by setting <code>overflow: hidden<\/code> on the <code>BODY<\/code> element, Carroll has <em>not<\/em> forced all other sections to not have scrollbars. Actually, <code>overflow: hidden<\/code> on the <code>BODY<\/code> or <code>HTML<\/code> element is a special directive. It tells the browser, &#8220;Don&#8217;t generate scrollbars for the <em>viewport itself<\/em>,&#8221; i.e. the pane that contains the overall HTML page.<\/p>\n<p>Thus, Carroll has doublefucked his code. Because he doesn&#8217;t understand how overflow works, his excess content will always flow down below the viewport. Ordinarily this would be fine &#8212; the user could scroll down as usual. But Carroll has told the browser to delete his scrollbars.  The end result is a completely borked web page, albeit one that works in IE.<\/p>\n<p>There are three lessons to be drawn.<\/p>\n<p>First, if you want to simulate a framed page, use frames. (Or use <code>position: fixed<\/code>, if you don&#8217;t care about IE.)<\/p>\n<p>Second, IE&#8217;s buggy behavior is a major barrier for competing browsers. The typical web designer is not someone who dutifully reads the specs; he is someone with a mental model based on trial-and-error, mystical <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cargo_cult\" title=\"explanation of cargo cult science\">cargo cult<\/a> coding. Does it work in IE? It does? Oh good, we&#8217;re done. If the alternative browsers can drive their marketshare high enough, this problem will start to go away. Until then, Firefox, Safari, and Opera will always be blamed for IE&#8217;s shortcomings. <\/p>\n<p>Third, validation is the <em>starting point for good design, not the end goal<\/em>. For any web page design, there is an enormous set of possible design problems. Validation reduces this set to a much smaller size, but does not eliminate it. As Carroll aptly demonstrates, it is easy to create a valid page that is totally screwed up. Still,<a href=\"http:\/\/diveintomark.org\/archives\/2003\/05\/05\/why_we_wont_help_you\" title=\"a Mark Pilgrim classic\">validation is one of the best tools in your toolbox<\/a> for eliminating basic rendering issues. Unless you are using XHTML (and at most only a couple hundred of you really are), this is by far the best practical reason to validate your pages. Probably the only practical reason. But that&#8217;s a story for another day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First, Carroll has set the height and width of his scrollable section to &#8220;100%&#8221; instead of a fixed size. This means that the box automatically expands as large as it needs to be to contain its content. Therefore Carroll&#8217;s scrollable section always is large enough to contain all of its content; therefore overflow never kicks in; therefore the section never generates the desired scrollbars, no matter how much &#8220;Bah Humbug&#8221; text Carroll adds.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":0,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}