<?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>Josh on the Web &#187; HTML</title>
	<atom:link href="http://joshduck.com/blog/category/programming/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://joshduck.com/blog</link>
	<description>It's a blog about the web, by Josh. Geddit?</description>
	<lastBuildDate>Thu, 17 Feb 2011 11:57:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Fix your tables: how to stop cells from expanding out of control</title>
		<link>http://joshduck.com/blog/2010/03/23/fix-your-tables-and-stop-cells-from-expanding/</link>
		<comments>http://joshduck.com/blog/2010/03/23/fix-your-tables-and-stop-cells-from-expanding/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 21:26:30 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://joshduck.com/blog/?p=138</guid>
		<description><![CDATA[HTML tables receive a bit of a bad rap thanks to years of abuse in web design, however in reality they&#8217;re semantic as the next element. They do have their quirks though, one common problem is that instead of aligning themselves like the rigid blocks we&#8217;re used to they tend to be a bit more [...]]]></description>
			<content:encoded><![CDATA[<p>HTML tables receive a bit of a bad rap thanks to years of abuse in web design, however in reality they&#8217;re semantic as the next element. They do have their quirks though, one common problem is that instead of aligning themselves like the rigid <code>blocks</code> we&#8217;re used to they tend to be a bit more fluid &#8211; expanding and contracting to fit their content.</p>
<p>This useful behaviour can become frustrating when a carefully laid-out table encounters abnormal input and suddenly decides to stop paying attention to the cell widths we&#8217;ve specified. Luckily there is a simple solution to this. All the major browsers implement an alternative <code>fixed</code> table layout which is specified through the appropriately named <code>table-layout</code> CSS property.<span id="more-138"></span></p>
<p>The demo table below should be 200 pixels wide, with each column taking up 50% of the total width. With the default layout enabled the last word clearly pushes the table beyond these dimensions. You can toggle the <code>table-layout</code> between <code>fixed</code> and <code>auto</code> (the default) to see the differences.</p>
<style type="text/css">
#example-table {
border: 1px solid white;
border-collapse: collapse;
width: 200px;
overflow: auto;
}
#example-table th,
#example-table td, {
border: 1px solid white;
width: 50%;
overflow: auto;
}
</style>
<h3>Top 5 Words</h3>
<table id="example-table">
<tbody>
<tr>
<th class="word">Word</th>
<th class="frequency">Frequency</th>
</tr>
<tr>
<td>Bite</td>
<td>5,631</td>
</tr>
<tr>
<td>My</td>
<td>6,405</td>
</tr>
<tr>
<td>Shiny</td>
<td>7,435</td>
</tr>
<tr>
<td>Metal</td>
<td>8,682</td>
</tr>
<tr>
<td>Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz</td>
<td>109,392</td>
</tr>
</tbody>
</table>
<p><button id="example-toggle">Set table-layout to fixed</button><br />
<script type="text/javascript">// <![CDATA[
(function(){
	var toggle = document.getElementById('example-toggle');
	var table = document.getElementById('example-table');
	var layout = 'auto';
	toggle.onclick = function() {
		toggle.innerHTML = 'Set table-layout to ' + layout;
		layout = layout == 'auto' ? 'fixed' : 'auto';
		table.style.tableLayout = layout;
	}
})();
// ]]&gt;</script></p>
<p>On a related node, you&#8217;ll notice that <code>overflow: hidden</code> has no effect on table cells. You&#8217;ll have to wrap the cell contents in a container element if you want to crop it.</p>
<p>This simple CSS property tends to go a unnoticed, but when you need it you&#8217;ll definitely be thankful it&#8217;s there.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshduck.com/blog/2010/03/23/fix-your-tables-and-stop-cells-from-expanding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

