<?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>Caffeine &#187; Search Results  &#187;  dynamic_page_tabs_in_ie6</title>
	<atom:link href="http://blog.onehub.com/?s=dynamic_page_tabs_in_ie6&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.onehub.com</link>
	<description>Onehub.com</description>
	<lastBuildDate>Thu, 09 Sep 2010 00:05:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Dynamic Page Tabs in IE6</title>
		<link>http://blog.onehub.com/posts/dynamic-page-tabs-in-ie6</link>
		<comments>http://blog.onehub.com/posts/dynamic-page-tabs-in-ie6#comments</comments>
		<pubDate>Fri, 02 Jan 2009 16:10:00 +0000</pubDate>
		<dc:creator>Charles Mount</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://blog.onehub.com/posts/dynamic-page-tabs-in-ie6</guid>
		<description><![CDATA[While working to ensure that the Onehub experience was of the best possible quality for our Internet Explorer 6 users, I ran in to a unique challenge: we have page tabs that need to be completely flexible. I had no guarantee that they would be a certain width, height, or even how many tabs there [...]]]></description>
			<content:encoded><![CDATA[<p>While working to ensure that the Onehub experience was of the best possible quality for our Internet Explorer 6 users, I ran in to a unique challenge: we have page tabs that need to be completely flexible.  I had no guarantee that they would be a certain width, height, or even how many tabs there would be.</p>
<p>Anyone who has worked with <abbr title="Internet Explorer 6">IE6</abbr> for long enough will know what a headache scenario that can be, but I needed to make sure that these tabs were as usable in IE6 as they were in any other browser.  After doing no small amount of research, I realized that very few people have written about how they have solved this problem; in fact, I found very few examples of tabs that were as complex as ours were.  So, I had to solve the problem for myself, and this is what I did.</p>
<p><em>Note: You can see this code in action on the <a href="http://onehub.com/blog/demos/dynamic_tabs_ie6">demo page</a>.</em></p>
<h3>Laying the Foundation</h3>
<h4>The <abbr title="Hypertext Markup Language">HTML</abbr></h4>
<p>To build the tabs that we use in our Hubs, we use an unordered list, with each list item containing a link</p>
<pre><code>&lt;li&gt;
  &lt;h2&gt;
    &lt;a class="page" href="#"&gt;
      &lt;span&gt;Files&lt;/span&gt;

    &lt;/a&gt;
  &lt;/h2&gt;
&lt;/li&gt;
</code></pre>
<p>To make designing new themes easier, and to add some flexibility to the tabs, the links are wrapped in an <code>H2</code> (though any block level element would work), and each link’s text is wrapped in a <code>span</code>.  While this does add a bit of bloat to the code, it also makes the tab a much more extensible object.</p>
<h4>Standards-based <abbr title="Cascading Stylesheet">CSS</abbr></h4>
<p>The approach that we used to get our tabs to display properly was to float the list items, removing all default margins/padding.  We set up the list and list items to be wrappers for the links.  The design of the tab is applied to the anchor (<code>a</code>) and <code>span</code> tags that live within the list item.</p>
<p>It actually doesn’t take a lot of code to get this to work properly, but a little bit of planning ahead can save some trouble in the long run.</p>
<pre><code>.pages ul {
  list-style-type: none;
  overflow: hidden; /* Float clearing for good browsers */
}

.pages ul li {
  float: left;
  position: relative;
}

.pages ul li a.page {
  display: block;
}

</code></pre>
<h3>Now, to make it all work in IE6</h3>
<p>There are multiple hurdles that need to be overcome in order to make this work properly.  Not only are there the normal issues with floated elements, but there’s the added issue of the  tabs being both floated and dynamic.</p>
<h4>Standard IE6 Tab Hacks</h4>
<p>To start off, I applied a few common IE hacks to the tabs. Before anything else, I set to the width of my containing <code>div</code> (<code>.pages</code>) to 100%.  I didn’t do this in my main stylesheet because the only browser that needs this is IE6, since all that does is clear our floats.</p>
<p>Then I apply the <a href="http://www.communitymx.com/content/article.cfm?page=1&amp;cid=C37E0">Holly Hack</a> (setting the height of an object to 1% in order to get a background color/image to display across the entirety of that object).  This gets applied to the containing <code>ul</code>, while the <code>li</code> elements have both a width and height of 1% applied to them.  Although this serves to help ensure that IE won’t do anything weird to our floats, I’m actually not using the width to make sure that the floats occur like we would expect.</p>
<p>My goals here are simple: first off, I want to make sure that any background that gets applied to the tabs wraps all the way around the contained elements.  More importantly though, this prevents blow outs.  Later on I’m going to apply some rules to the anchor and span tags that will cause all sorts of problems if we don’t prevent it beforehand.</p>
<h4>Keeping My Ducks in a Row</h4>
<p>To make sure that my text doesn’t wrap, I apply <code>white-space: nowrap</code> to the <code>li</code>.  Rarely do you want your text to wrap when laying out tabs, since that will force the height of the tab to become inconsistent.</p>
<p>However, by setting a width of 1% on the <code>li</code>, you can expect to see your text wrap.  By telling the browser not to wrap that text, you can maintain the integrity of your design.</p>
<pre><code>.pages {
  width: 100%;
}

.pages ul {
  height: 1%;
}

.pages ul li {
  height: 1%;
  width: 1%;
  white-space:nowrap;
}
</code></pre>
<p>So now that our wrappers are behaving properly, and will prevent unsightly blow outs, let’s move on to the final piece: the links.</p>
<h4>Highly Interactive Anchor Tabs</h4>
<p>One of the things that I needed to do in this situation was to set height and width of the anchor to 100% in addition to declaring the anchor tag as a block element (remember that blow out that I was talking about?  This is the first place that will happen).  This tells IE6 that any padding that is applied to the link (so, the background of the tab) is to be a link, not just the text.</p>
<pre><code>.pages ul li a.page {
  width: 100%;
  height: 100%;
}
</code></pre>
<h4>Adding in some Fine Grained Control</h4>
<p>Our tabs also have a secondary state when the Hub is put in to Design Mode, where the user can fully customize their Hub. This mode affects the tabs in that some of the design changes, but also there are two more anchor tags added in, as well as a background image (and some javascript) to make the tabs fully editable.</p>
<p>Finally, we can focus on the <code>span</code> tag. This tag has two declarations added to it in the Hacks sheet; a width of 100% to make sure that it occupies the full tab area, and a display setting of “<code>block</code>”.  The latter is crucial if you are planning on using any icons for your tabs.  In our example, the icon that gets used is a cross to indicate that the tab can be moved.</p>
<pre><code>.design .pages ul li.moveable a.page span {
  display: block;
  width: 100%;
}
</code></pre>
<h3>In Conclusion</h3>
<p>By leveraging IE6’s quirks through tricks like the Holly Hack, and using some smart CSS, I made sure that our tabs worked smoothly in IE6.  I can’t emphasize enough how starting with code that is both valid and semantic made this whole process easier, since that allowed me to focus only on the issues that were being raised by Internet Explorer 6. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.onehub.com/posts/dynamic-page-tabs-in-ie6/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
