<?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>tjameswhite &#187; media queries</title>
	<atom:link href="http://tjameswhite.com/archives/tag/media-queries/feed/" rel="self" type="application/rss+xml" />
	<link>http://tjameswhite.com</link>
	<description>My infrequent thoughts, ideas and ramblings.</description>
	<lastBuildDate>Thu, 08 Dec 2011 02:10:25 +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>Rethinking a Table with Media Queries</title>
		<link>http://tjameswhite.com/archives/rethinking-a-table-with-media-queries/</link>
		<comments>http://tjameswhite.com/archives/rethinking-a-table-with-media-queries/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 02:58:54 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[(x)HTML]]></category>
		<category><![CDATA[@media]]></category>
		<category><![CDATA[media queries]]></category>
		<category><![CDATA[table data]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://tjameswhite.com/?p=535</guid>
		<description><![CDATA[Attending An Event Apart Boston and going through the W3C&#8217;s Mobile Web Best Practices course has me looking more closely at how I mark up data. The main cord that was struck, most directly in Luke Wroblewski&#8217;s Mobile First! talk, but echoed by most every speaker in Boston, is to design from the mobile version [...]]]></description>
			<content:encoded><![CDATA[<p>Attending <a href="http://aneventapart.com/2010/boston/" rel="external">An Event Apart Boston</a> and going through the <acronym title="World Wide Web Consortium">W3C</acronym>&#8217;s <a href="http://www.w3.org/2010/03/MobiWeb107/" rel="external">Mobile Web Best Practices</a> course has me looking more closely at how I mark up data. </p>
<p>The main cord that was struck, most directly in Luke Wroblewski&#8217;s Mobile First! talk, but echoed by most every speaker in Boston, is to design from the mobile version of your site <strong>first</strong>.  This theme occurs in the Mobile Web course as well.<br />
<span id="more-535"></span><br />
For exercises in the Mobile Web course we have to consider mark up that is mobile friendly. Consider, if you will, a simple data table. In a desktop browser, a table is easy enough to render. See, a <a href="/demos/media-queries/simple-table.html">simple data table</a>. </p>
<p>However, on a mobile device with its much narrower screen, a table simply won&#8217;t fit. Instead, the data may be better presented in an alternate form, such as a definition list. (Please note, this is but one example and does not mean that all tables can be equated to a definition list.)</p>
<p>Call me Marie, but I want to have my cake and eat it to.</p>
<h3>Enter the Media Query</h3>
<p>So what is a media query? There are <a href="http://www.google.com/search?hl=en&amp;q=css%20media%20query&amp;aq=f&amp;oq=" rel="external">lots of resources out there</a>. Let me sum it up: media queries allow you to specify CSS rules base not on a device, but on a set of circumstances.</p>
<p>The following block of code applies to any device that claims to be a screen. It will simply make level 1 headers blue:</p>
<pre><code>@media screen {
  h1 {color: blue;}
}</code></pre>
<p>Let&#8217;s through a query into the mix:</p>
<pre><code>@media screen <ins>and (max-width: 500px)</ins>  {
  h1 {color: red;}
}</code></pre>
<p>Now the style applies to any device that claims to be a screen <strong>and</strong> has a width of 500px or less. There are several other properties that can be queried, but this works for our demo.</p>
<p>Let&#8217;s put a query into play on this <a href="/demos/media-queries/floating-query.html">simple demo page</a>. You should see a green masthead across the top of the page and two gray boxes sitting next to each other. Now narrow your browser.</p>
<p>When your browser gets to 500px wide you should see the green masthead change to gray and the gray boxes become blue and stack on top of each other. The code is quite simple:</p>
<pre><code>@media all and (max-width: 500px)  {
	#header {background: #ddd;} /* little color change */
	.column {
		float: none; /* linearize */
		width: 95%; /* reset width */
		background: #6374AB;
		color: #FFF;
		}
}</code></pre>
<h3>The Trouble with Tables</h3>
<p>Let&#8217;s take the same page and <a href="/demos/media-queries/data-table.html">add our simple table to it</a>. Looks fine so far, right? Now narrow your browser.</p>
<p>Once again at the threshold of 500px you should see the boxes stack and the colors change. But this time there is a horizontal scroll because the table needs to be wide enough for it&#8217;s content.</p>
<p>The problem: we came at this from the desktop first. What if we reversed that and thought about the small screen first, then adapted it for the desktop?</p>
<h3 lang="fr">Ce n&#8217;est pas une table</h3>
<p>For our little demo, it isn&#8217;t too difficult to re-imaging that <a href="/demos/media-queries/definition-list.html">tabular data as a definition list</a> (or series of list in this case), which should work nicely on most any mobile device. The code looks something like this:</p>
<pre><code>&lt;dl&gt;
	&lt;dt&gt;Ekstr&ouml;m&lt;/dt&gt;
	&lt;dd&gt;&lt;span class="label"&gt;Points: &lt;/span&gt;44&lt;/dd&gt;
	&lt;dd&gt;&lt;span class="race"&gt;Race 1: &lt;/span&gt;10&lt;/dd&gt;
	&lt;dd&gt;&lt;span class="race"&gt;Race 2: &lt;/span&gt;2&lt;/dd&gt;
	&lt;dd&gt;&lt;span class="race"&gt;Race 3: &lt;/span&gt;-&lt;/dd&gt;
&lt;/dl&gt;</code></pre>
<p>So we&#8217;ve got our cake. Now to eat it too.</p>
<p>Definition lists are just fine in a desktop browser, but I really want this to be more table-like.</p>
<p>You&#8217;ll notice that there are already some <code>class</code> attributes. We just need to add a little more markup to create what will become the table headers:</p>
<pre><code>&lt;div class="head"&gt;
  &lt;div class="row"&gt;
	&lt;div class="dataHead"&gt;&lt;abbr title="position"&gt;Pos.&lt;/abbr&gt;&lt;/div&gt;
	&lt;div class="dataHead"&gt;Driver&lt;/div&gt;
	&lt;div class="dataHead"&gt;&lt;abbr title="points"&gt;Pt.&lt;/abbr&gt;&lt;/div&gt;
	&lt;div class="dataHead"&gt;Hockenheim&lt;/div&gt;
	&lt;div class="dataHead"&gt;Oscherslebe&lt;/div&gt;
	&lt;div class="dataHead"&gt;EuroSpeedway&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;</code></pre>
<p>and style with <code>display: table</code> and related properties. For example:</p>
<pre><code>dl, .row {display: table-row;}
.dataHead, dd, dt {display: table-cell;}</code></pre>
<p>(<a href="/demos/media-queries/data-list.css">View the complete CSS</a>)</p>
<p>We now have markup that is mobile friendly styled in a desktop friendly way. All that is left is to undo those desktop styles for small screen display using our media query. Mostly this involves <code>display: block</code> to counteract the table display properties.</p>
<p>The end result: a <a href="/demos/media-queries/data-list.html">desktop and mobile friendly web page</a>. Once again, with a device wider than 500px you should see green color and a basic table. Narrow your browser to less than 500px &hellip; presto! our definition list re-emerges.</p>
<p>I&#8217;ve used a similar media query on this site. Narrow your browser and it should revert to one column.</p>
<h3>Caveat</h3>
<p>No, this is not a perfect solution. It is <em>a</em> solution. If you look at the full code you will see some markup that may be questionable (the first <code>dd</code> in the lists). I merely present this to get us all thinking about they way we think about and markup data.</p>
<p>Your mileage may vary; use at your own risk; objects in mirror may be close than they appear; etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://tjameswhite.com/archives/rethinking-a-table-with-media-queries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

