<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Paul Rohde</title>
	
	<link>http://www.paulrohde.com</link>
	<description>Photographer, Developer, Graphic Designer</description>
	<lastBuildDate>Wed, 11 Jan 2012 22:09:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/paulrohdecom" /><feedburner:info uri="paulrohdecom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/paulrohdecom" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsalloy.com/?rss=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.newsalloy.com/subrss3.gif">Subscribe with NewsAlloy</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.yourminis.com/subscribe.aspx?u=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.yourminis.com/images/addtoyourminisbadge.gif">Subscribe with Yourminis.com</feedburner:feedFlare><feedburner:feedFlare href="http://download.attensa.com/app/get_attensa.html?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.attensa.com/blogs/attensa/WindowsLiveWriter/BadgeredintoBadges_10C02/attensa_feed_button5.gif">Subscribe with Attensa for Outlook</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://hub.netomat.net/account/account.autoSubscribe.jspa?urls=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.netomat.net/blogger/images/icon_netomat_feedbutton.gif">Subscribe with netomat Hub</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2Fpaulrohdecom" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
		<title>Font Hybridization in HTML 5</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/GpxqkjfIzx8/</link>
		<comments>http://www.paulrohde.com/font-hybridization-in-html-5/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 22:09:54 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[Cufon]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[Google Web Fonts]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[TypeKit]]></category>
		<category><![CDATA[Typeography]]></category>
		<category><![CDATA[Web Fonts]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1621</guid>
		<description><![CDATA[Over this Christmas break, I was over at a friends house and got to sit down and tinker with my friends Mac. I&#8217;d forgotten how good fonts look, and I suddenly realized why so many sites are now using custom web fonts. Since I primarily use Windows at work and at home, I get annoyed [...]]]></description>
			<content:encoded><![CDATA[<p>Over this Christmas break, I was over at a friends house and got to sit down and tinker with <a href="http://www.jordanogren.com">my friends</a> Mac. I&#8217;d forgotten how <em>good</em> fonts look, and I suddenly realized why so many sites are now using custom web fonts. Since I primarily use Windows at work and at home, I get annoyed by fonts that are difficult to read or that don&#8217;t render well on the screen. Somehow, I&#8217;ve never been 100% happy with font rendering on windows. It&#8217;s been getting better, but it&#8217;s still not as good as a Mac is. Maybe its the screen, maybe its the OS, maybe its the app, maybe its a combination of all of the above. Because I&#8217;ve been on this HTML kick, and I&#8217;m on windows, I&#8217;ve tended toward <a href="http://cufon.shoqolate.com">Cufon</a> as my font replacement tool of choice when building sites since it&#8217;s the only one that produces a &#8220;more-reasonable&#8221; output on my machine.</p>
<p>But Cufon by it&#8217;s nature has several drawbacks. First, you can&#8217;t copy and paste text rendered with Cufon. With most of the newer browsers you can select it, but there&#8217;s not much more you can do beyond that. So, I usually limit Cufon usage to titles, headers, and the more &#8220;design-ery&#8221; aspects of a page. Second, because Cufon is image based, if someone zooms in on your text beyond 100% Cufon rendered text gets all fuzzy the same way it would if you zoomed in on an image. And finally, because Cufon renders with javascript on the client, there&#8217;s no way to cache the text. Javascript is fast, but when you&#8217;re rendering a large amount of text on a phone, there&#8217;s usually not a good way around a flash of unstyled content. And it happens each time you go to a new page because it can&#8217;t be cached.</p>
<p>Web fonts on the other hand, allow you to use fonts in a very similar manner as if you had them installed on your device with native rendering by the OS. You can select, copy, paste, and use it as you would any other piece of text. Web fonts are cacheable, so although you could get a flash of unstyled content when you first visit a page, subsequent visits should render immediately. The disadvantage however, is the OS. On windows, the rendering of fonts just&#8230; Sucks. So people don&#8217;t use it.</p>
<p><em>But what if there was a way to do a hybrid between Cufon and Web Fonts?</em></p>
<p>Besides the rendering issue, Web Fonts <strong>are</strong> the best option. They&#8217;re the most flexible and the most future proof. But they still suffer on Windows, some phones, and on older browsers that don&#8217;t support the new <code>@font-face</code> CSS syntax. So what if we did a hybrid? Use <code>@font-face</code>, then fall back on Cufon for older browsers, and for windows. The advantage is that on a new browser the<code>@font-face</code>&#8216;s will be cached, used for the initial rendering of the page, and then cleaned up with Cufon later.</p>
<p>Using Modernizr and a little custom javascript to do user agent testing I put together a page to test out the hybrid font idea:</p>
<p><a href="http://www.paulrohde.com/demo/cufon-hybrid/demo.html">http://www.paulrohde.com/demo/cufon-hybrid/demo.html</a></p>
<p>It&#8217;s a rough draft. I have some screen shots below from both Mac and PC&#8217;s (click for full size versions). </p>
<h1>Mac</h1>
<p><a href="http://media.paulrohde.com/blog/2012/01/hybrid-mac-full.png" rel="lightbox"><img src="http://media.paulrohde.com/blog/2012/01/hybrid-mac-full.png" alt="" title="hybrid-mac-full" class="alignnone size-full wp-image-1624" /></a><br />
<a href="http://media.paulrohde.com/blog/2012/01/hybrid-mac-zoomed.png" rel="lightbox"><img src="http://media.paulrohde.com/blog/2012/01/hybrid-mac-zoomed.png" alt="" title="hybrid-mac-zoomed"  class="alignnone size-full wp-image-1625" /></a></p>
<h1>PC</h1>
<p><a href="http://media.paulrohde.com/blog/2012/01/hybrid-win-full.png" rel="lightbox"><img src="http://media.paulrohde.com/blog/2012/01/hybrid-win-full.png" alt="" title="hybrid-win-full" class="alignnone size-full wp-image-1622" /></a><br />
<a href="http://media.paulrohde.com/blog/2012/01/hybrid-win-zoomed.png" rel="lightbox"><img src="http://media.paulrohde.com/blog/2012/01/hybrid-win-zoomed.png" alt="" title="hybrid-win-zoomed" class="alignnone size-full wp-image-1623" /></a></p>
<p>For simplicity, the javascript code to test and load Cufon and my custom cufon polyfill looks like this:</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> rendersNiceFontface<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	result = navigator.<span style="color: #006600;">appVersion</span>.<span style="color: #006600;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Win&quot;</span><span style="color: #66cc66;">&#41;</span> != <span style="color: #CC0000;">-1</span>
		|| navigator.<span style="color: #006600;">appVersion</span>.<span style="color: #006600;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Android&quot;</span><span style="color: #66cc66;">&#41;</span> != <span style="color: #CC0000;">-1</span>;
	<span style="color: #000066; font-weight: bold;">return</span> result;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> supportsNiceFontface = !rendersNiceFontface<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
Modernizr.<span style="color: #006600;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>
	<span style="color: #66cc66;">&#123;</span>
		test : Modernizr.<span style="color: #006600;">fontface</span> &amp;&amp; Modernizr.<span style="color: #006600;">canvas</span> &amp;&amp; supportsNiceFontface,
&nbsp;
		nope : <span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">'cufon-yui.js'</span>, <span style="color: #3366CC;">'BebasNeueRegular_400.font.js'</span>, <span style="color: #3366CC;">'cufon-polyfill.js'</span> <span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;</pre>
<p>Using the <a href="http://www.modernizr.com/">Modernizr</a> <a href="http://yepnopejs.com/">yepnope.js</a>, I&#8217;m able to completely skip loading Cufon at all if the browser supports good <code>@font-face</code> rules. There&#8217;s more that I&#8217;d have to do to clean it up before I&#8217;d use it in a real setting, but it demonstrate the concept, and is something I could definitely use later as a <code>@font-face</code> polyfill. It does have some drawbacks though, you have to maintain both your CSS rules and your Cufon replacement calls, and Cufon doesn&#8217;t work well with a large amount of body text, so if you don&#8217;t support <code>@font-face</code>, I&#8217;d fall back to a good secondary font and forgo Cufon in those cases.</p>
<p>I hope this got some gears turning, I&#8217;m looking forward to some comments.</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/GpxqkjfIzx8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/font-hybridization-in-html-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/font-hybridization-in-html-5/</feedburner:origLink></item>
		<item>
		<title>CSS Is A Lie.</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/FxIrcvIOCpE/</link>
		<comments>http://www.paulrohde.com/css-is-a-lie/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 22:05:54 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[stylesheets]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1616</guid>
		<description><![CDATA[According to Wikipedia: Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation semantics (the look and formatting) of a document written in a markup language. Furthermore: CSS specifies a priority scheme to determine which style rules apply if more than one rule matches against a particular element. In this so-called [...]]]></description>
			<content:encoded><![CDATA[<p>According to Wikipedia:</p>
<blockquote><p>Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation semantics (the look and formatting) of a document written in a markup language.
</p></blockquote>
<p>Furthermore:</p>
<blockquote><p>CSS specifies a priority scheme to determine which style rules apply if more than one rule matches against a particular element. In this so-called cascade, priorities or weights are calculated and assigned to rules, so that the results are predictable.
</p></blockquote>
<p>From my informal office survey, the general consensus is that <em>the most important thing&#8482;</em> in CSS is that everything &#8216;cascades&#8217; correctly. That is, that rules and styles defined further down in a CSS document override styles specified further up in the document (excluding the <code>!important</code> operator of course, which you should not be using anyways). It makes sense if you think about it, after all it&#8217;s not called a <strong>Cascading</strong> Style Sheet for nothing.</p>
<p>Now, the test. Given the following HTML and CSS snippet, what color will the two paragraphs be?</p>
<p>HTML</p>
<pre>&lt;p id=&quot;myid&quot; class=&quot;myclass&quot;&gt;
   Hello World.
&lt;/p&gt;
&nbsp;
&lt;p class=&quot;myclass&quot;&gt;
   This is another line of text
&lt;/p&gt;</pre>
<p>CSS</p>
<pre class="css"><span style="color: #cc00cc;">#myid</span> <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">red</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.myclass</span> <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #000000; font-weight: bold;">blue</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
p <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">green</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>The Answer:<br />
Hello World is red, the second line of text is blue.</p>
<p>Don&#8217;t believe me? <a href="http://www.paulrohde.com/demo/html/CSSLie.html">I put up a demo page with just the html and css here.</a></p>
<p>After a decent amount of Googling and reading blogs and the <a href="http://www.w3.org/TR/CSS2/cascade.html#specificity">W3C Spec on CSS Selectors</a>, I realize now how styles are calculated and applied, but seems to go completely against the &#8216;cascading&#8217; nature of style sheets since the cascading nature of style sheets only applies when the &#8216;specificity&#8217; values are the same.</p>
<p>For example, the following snippet behaves as you would expect:</p>
<p>CSS</p>
<pre class="css">p <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">gray</span>;
   <span style="color: #000000; font-weight: bold;">font-size</span>: <span style="color: #933;">20px</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* ... later ... */</span>
&nbsp;
p <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">green</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>As you might expect the paragraph will be green, and have a font size of 20px. The rule that is more specific selectors takes precedence over rules that are less specific regardless of where that rule is declared in the markup. You can mentally calculate how specific a rule by the &#8216;level&#8217; and number of the selectors used. From low to high, you have </p>
<ol>
<li>Element and pseudo elements such as <code>p</code>, <code>a</code>, <code>span</code>, <code>div</code>, :first-line </li>
<li>Class, attributes, pseudo-classes <code>.myclass </code></li>
<li>Id attributes <code>#myelement</code> <code>#theonething</code> </li>
<li>From inline style attributes </li>
<li><code>!important</code></li>
</ol>
<p>If there&#8217;s anything of a higher level, the higher level overrides the lower level style, and if they&#8217;re the same level, the higher count wins, and if they&#8217;re at the same level with the same count (<code>.myclass</code>, and <code>.myotherclass</code>) then the one further down takes precedence, this is the &#8220;only&#8221; time cascading actually happens.</p>
<p>Its something that is unfortunately very subtle because of the way we write CSS, your taught from the begin to start with the most basic generic styles and work your way through the more specific styles. While this is correct, it&#8217;s very easy to go for a long time without running into a situation where a more specific styles.</p>
<p>I had no idea up until about a week ago that CSS worked like this. I always assumed that specificity was only used to select the subset of elements the rule applied to, and that if you applied a more general rule after a more specific rule that the more general rule would overwrite anything earlier. This is obviously not the case. If you want to read more, here&#8217;s some links to a few more comprehensive articles on the subject:</p>
<p>CSS Specificity and Inheritance: <a href="http://coding.smashingmagazine.com/2010/04/07/css-specificity-and-inheritance/">http://coding.smashingmagazine.com/2010/04/07/css-specificity-and-inheritance/</a></p>
<p>Star Wars and CSS Specificity: <a href="http://www.stuffandnonsense.co.uk/archives/css_specificity_wars.html">http://www.stuffandnonsense.co.uk/archives/css_specificity_wars.html</a></p>
<p>Specifics on CSS Specificity: <a href="http://css-tricks.com/855-specifics-on-css-specificity/">http://css-tricks.com/855-specifics-on-css-specificity/</a></p>
<p>Art and Zen of CSS: <a href="http://donttrustthisguy.com/2010/03/07/the-art-and-zen-of-writing-css/">http://donttrustthisguy.com/2010/03/07/the-art-and-zen-of-writing-css/</a></p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/FxIrcvIOCpE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/css-is-a-lie/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/css-is-a-lie/</feedburner:origLink></item>
		<item>
		<title>EventHandler&lt;T&gt; or Action&lt;T&gt;</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/FmOnhriB5YU/</link>
		<comments>http://www.paulrohde.com/events-eventhandler-or-action/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 19:33:21 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Action]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[Patterns and Practices]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1598</guid>
		<description><![CDATA[If you&#8217;ve used C# for any length of time, you&#8217;ve used events. Most likely, you wrote something like this: &#160; public class MyCoolCSharpClass &#123; public event EventHandler MyCoolEvent; &#125; &#160; public class MyOtherClass &#123; public void MyOtherMethod&#40;MyCoolCSharpClass obj&#41; &#123; obj.MyCoolEvent += WhenTheEventFires; &#125; &#160; private void WhenTheEventFires&#40;object sender, EventArgs args&#41; &#123; Console.WriteLine&#40;&#34;Hello World!&#34;&#41;; &#125; &#125; [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve used C# for any length of time, you&#8217;ve used events. Most likely, you wrote something like this:</p>
<pre class="csharp">&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MyCoolCSharpClass <span style="color: #000000;">&#123;</span>
     <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> EventHandler MyCoolEvent;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MyOtherClass <span style="color: #000000;">&#123;</span>
     <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> MyOtherMethod<span style="color: #000000;">&#40;</span>MyCoolCSharpClass obj<span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          obj.<span style="color: #0000FF;">MyCoolEvent</span> += WhenTheEventFires;
     <span style="color: #000000;">&#125;</span>
&nbsp;
     <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> WhenTheEventFires<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs args<span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Hello World!&quot;</span><span style="color: #000000;">&#41;</span>;
     <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>Later, you need parameters to be passed in along with the event, so you changed it to something like this:</p>
<pre class="csharp">&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> EventHandler&lt;MyEventArgs&gt; MyCoolEvent;
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MyEventArgs : EventArgs
<span style="color: #000000;">&#123;</span>
     <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Name <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span>
     <span style="color: #0600FF;">public</span> DateTime WhenSomethingHappened <span style="color: #000000;">&#123;</span> get; set; <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
...
     <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> WhenTheEventFires<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, MyEventArgs args<span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          var theCoolCSharpSendingClass = <span style="color: #000000;">&#40;</span>MyCoolCSharpClass<span style="color: #000000;">&#41;</span>sender;
          Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Hello World! Good to meet you &quot;</span> + args.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>;
     <span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>You add two or three more events, some property change and changing events, and finally a class with about 4 properties, 3 events, and a little bit of code now has 3 supporting <code>EventArgs</code> classes, casts for every time you need the sender class instance (In this example, I&#8217;m assuming the event is always fired by <code>MyCoolCSharpClass</code>, and not through a method from a 3rd class). There&#8217;s a lot of code there to maintain even for just a simple class with some very simple functionality.</p>
<p>Lets look at this for a minute. First, <code>EventHandler</code> and <code>EventHandler&lt;T&gt;</code> are simply delegates, nothing more nothing less (If you&#8217;re not sure what a delegate is, don&#8217;t sweat it, it&#8217;s not really the point of this discussion). What makes the magic happen for events is that little event keyword the prefaces the event that turns that internally turns the delegate type into a subscribe-able field. Essentially, it simplifies adding and removing multiple methods that are all called when the event is invoked. With the introduction of generics in C# 2.0, and the introduction of LINQ in 3.5, we have generic forms of most of the delegates we could ever use in the form of <code>Action&lt;T1, T2, T3...&gt;</code> and <code>Func&lt;TRes, T1, T2...&gt;</code>. What this means, is that we can change an event declarations to use whatever delegate we want. Something like this is perfectly valid:</p>
<pre class="csharp">&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> Action&lt;MyCoolCSHarpClass, <span style="color: #FF0000;">string</span>, DateTime&gt; MyCoolEvent;
&nbsp;</pre>
<p>And what about when we subscribe? Well, now we get typed parameters:</p>
<pre class="csharp">&nbsp;
...
     <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> WhenTheEventFires<span style="color: #000000;">&#40;</span>MyCoolCSHarpClass sender, <span style="color: #FF0000;">string</span> name, DateTime theDate<span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Hello World! Good to meet you &quot;</span> + name<span style="color: #000000;">&#41;</span>;
     <span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>That&#8217;s cool. I&#8217;ve now reduced the amount of code I have to maintain from 4 classes to 1 and I don&#8217;t have to cast my sender. As a matter of fact, I don&#8217;t even have to pass a sender. How often have you written an event that&#8217;s something like this:</p>
<pre class="csharp">&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> EventHandler TheTableWasUpdatedGoCheckIt;
&nbsp;</pre>
<p>Whoever is subscribed to this event doesn&#8217;t care about who sent it, or what data specifically was updated, all the subscribe cares about was that it was fired, nothing more than that. Even then, in a &#8220;you can only use <code>EventHandler</code> delegate world&#8221; you&#8217;re still stuck creating a method to subscribe to the event that looks like this: </p>
<pre class="csharp">&nbsp;
     <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> WhenTheTableWasUpdated<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs args<span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          <span style="color: #008080; font-style: italic;">// Go check the database and update stuff...</span>
     <span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>If we use what we&#8217;ve learned and change the event to something like this:</p>
<pre class="csharp">&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> Action TheTableWasUpdatedGoCheckIt;
&nbsp;</pre>
<p>We can write our method like this:</p>
<pre class="csharp">&nbsp;
     <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> WhenTheTableWasUpdated<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          <span style="color: #008080; font-style: italic;">// Go check the database and update stuff...</span>
     <span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>Since we never cared about the parameters in the first place.</p>
<p>Thats awesome fine and dandy, but just blindly replacing every instance of <code>EventHandler</code> delegates to Actions isn&#8217;t always the best idea, there are a few caveats:</p>
<p>First, there are some practical physical limitations of using <code>Action&lt;T1, T2, T2... &gt;</code> vs using a derived class of <code>EventArgs</code>, three main ones that I can think of: </p>
<ul>
<li>If you change the number or types of parameters, every method that subscribes to that event will have to be changed to conform to the new signature. If this is a public facing event that 3rd party assemblies will be using, and there is any possibility that the number or type of arguments would change, its a very good reason to use a custom class that can later be inherited from to provide more parameters. Remember, you can still use an <code>Action&lt;MyCustomClass&gt;</code>, but deriving from EventArgs is still the <em>Way Things Are Done</em>&trade;</li>
<li>Using <code>Action&lt;T1, T2, T2... &gt;</code> will prevent you from passing feedback BACK to the calling method unless you have a some kind of object (with a Handled property for instance) that is passed along with the <code>Action</code>, and if you&#8217;re going to make a class with a handled property, making it derive from <code>EventArgs</code> is completely reasonable.</li>
<li>You don&#8217;t get named parameters by using <code>Action&lt;T1, T2 etc...&gt;</code> so if you&#8217;re passing 3 <code>bool</code>&#8216;s, an <code>int</code>, two <code>string</code>&#8216;s, and a <code>DateTime</code>, you won&#8217;t immediately know what the meaning of those values. Passing a custom args class provides meaning to those parameters.</li>
</ul>
<p>Secondly, consistency implications. If you have a large system you&#8217;re already working with, it&#8217;s nearly always better to follow the way the rest of the system is designed unless you have an very good reason not too. If you have publicly facing events that need to be maintained, the ability to substitute derived classes for args might be important.</p>
<p>Finally, real life practice, I personally find that I tend to create a lot of one off events for things like property changes that I need to interact with (Particularly when doing MVVM with view models that interact with each other) or where the event has a single parameter. Most of the time these events take on the form of <code>public event Action&lt;[classtype], bool&gt; [PropertyName]Changed;</code> or <code>public event Action SomethingHappened;</code>. In these cases, there are two benefits that you might be able to guess from what you&#8217;ve already seen. </p>
<ul>
<li>I get a type for the issuing class. If <code>MyClass</code> declares and is the only class firing the event, I get an explicit instance of <code>MyClass</code> to work with in the event handler.
<li>For simple events such as property change events, the meaning of the parameters is obvious and stated in the name of the event handler and I don&#8217;t have to create a myriad of classes for these kinds of events.
</ul>
<p>Food for thought. If you have any comments, feel free to leave them in the comment section below.</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/FmOnhriB5YU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/events-eventhandler-or-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/events-eventhandler-or-action/</feedburner:origLink></item>
		<item>
		<title>Line counting in Powershell</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/PAqRphQxDKw/</link>
		<comments>http://www.paulrohde.com/line-counting-in-powershell/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 21:44:10 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Line Counting]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Project Size]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1595</guid>
		<description><![CDATA[Quick Tip: If you want to do a line count on a project, a really easy way to do it is with a simple Powershell command: &#160; (dir -include *.cs,*.xaml -recurse &#124; select-string .).Count &#160; Add extension types as necessary. Note that it DOES include comments in the line count. Here&#8217;s the stackoverflow article where [...]]]></description>
			<content:encoded><![CDATA[<p>Quick Tip: If you want to do a line count on a project, a really easy way to do it is with a simple Powershell command:</p>
<pre>&nbsp;
(dir -include *.cs,*.xaml -recurse | select-string .).Count
&nbsp;</pre>
<p>Add extension types as necessary. Note that it DOES include comments in the line count.</p>
<p>Here&#8217;s the stackoverflow article where this originated from, I needed something that would run outside of the main solution to take into account all the additional projects and files, so a plugin was not going to work.</p>
<p><a href="http://stackoverflow.com/questions/1244729/how-do-you-count-the-lines-of-code-in-a-visual-studio-solution">http://stackoverflow.com/questions/1244729/how-do-you-count-the-lines-of-code-in-a-visual-studio-solution</a></p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/PAqRphQxDKw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/line-counting-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/line-counting-in-powershell/</feedburner:origLink></item>
		<item>
		<title>Designing for code: Copy &amp; Paste</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/7F4sA2znHtY/</link>
		<comments>http://www.paulrohde.com/designing-for-code-copy-paste/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 00:00:10 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[comatose]]></category>
		<category><![CDATA[Copy Paste]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Layout]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1591</guid>
		<description><![CDATA[As a developer, I&#8217;m constantly on the web. Learning, reading, finding solutions to problems or looking up odd bugs. There is a great community of developers that are constantly publishing solutions / fixes / workarounds / techniques for the benefit of their fellow developers. Being developers, you would expect to find that the sites they [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer, I&#8217;m constantly on the web. Learning, reading, finding solutions to problems or looking up odd bugs. There is a great community of developers that are constantly publishing solutions / fixes / workarounds / techniques for the benefit of their fellow developers. Being developers, you would expect to find that the sites they run are easy to use across the board! For the most part they are but every now and again though I run across a site that makes me want to bash my head against the monitor. Why? Because it breaks the simplest feature:</p>
<p>Copy. Paste.</p>
<p>If you EVER post code on the web on a site you control, or if you are in charge of a site where you or others post code. Make. Sure. Copy. Paste. Works. Period. I&#8217;m not just talking about &#8216;I can select it and paste it&#8217; functionality, I&#8217;m referring to those &#8216;code highlighting&#8217; plug ins that add line numbers to EVERY SINGLE LINE of a code snippet when you paste.</p>
<p>Don&#8217;t Do It.</p>
<p>There are lots of good highlighting plug ins out there, sites that will format your code for you, and so on. Whatever method you chose, test it and make sure you can use the code from your site without having to modify or do anything to it. If you can&#8217;t, abandon it. Find something else. Use raw text. Whatever it takes to get the basics working well.</p>
<p>In addition, make sure your code works well when the site is scaled up or down. If you have a site that doesn&#8217;t change width as the browser size changes, ignore this, and read this post on fluid layouts: <a href="http://www.paulrohde.com/on-modern-layouts-and-semi-fluid-grids/">http://www.paulrohde.com/on-modern-layouts-and-semi-fluid-grids/</a>. Now IF your site changes width, your code should ALWAYS work on whatever size the visitor is looking at the site on. Check it on a smart phone. Check it on a tablet. Stretch your site across two wide screen monitors. If it &#8216;breaks&#8217; (as in becomes unreadable or inaccessible) fix it. Go back to the basics. Remove / alter / don&#8217;t use a plugin. Again, do whatever it takes to make the basics work.</p>
<p>Don&#8217;t underestimate the importance of the small supposedly insignificant details. In all honesty, users aren&#8217;t going to come to your site and praise you for what an elegant job you did on making your code easy to copy and paste, or how nice the content looks, or how readable the article is. Its similar to the way people will notice spelling and grammar. If your sentences are well formed and correct and the article is well structured the person reading should never have to mentally think about it. On the other hand, if an article is not well crafted, that person will have to wade through the mistakes and mentally jump between what was actually written and what the author intended. In same way, whatever type of content you present to a visitor, it should always be presented it in such a way that the person consuming it can do so without ANYTHING getting in the way of them doing so effectively.</p>
<p>Think about it. Go check your site. Make the net a better place.</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/7F4sA2znHtY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/designing-for-code-copy-paste/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/designing-for-code-copy-paste/</feedburner:origLink></item>
		<item>
		<title>Invisible extra line height</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/21W6vVpeE50/</link>
		<comments>http://www.paulrohde.com/invisible-extra-line-height/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 23:00:41 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[line height]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1573</guid>
		<description><![CDATA[I came across this annoying off by one pixel layout issue several days ago when dealing with &#60;code&#62; tags. You may not even guess that its caused by it at first, but if you ever try to test your layout with a baseline script, you may notice this. Take a good look at the following [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this annoying off by one pixel layout issue several days ago when dealing with <code>&lt;code&gt;</code> tags. You may not even guess that its caused by it at first, but if you ever try to test your layout with a <a href="http://www.paulrohde.com/typesetter-hd/">baseline script</a>, you may notice this.</p>
<p>Take a good look at the following screenshot and tell me, are these two paragraphs the same height?</p>
<p><img src="http://media.paulrohde.com/blog/2011/11/ielh-1.png" alt="" title="ielh-1" width="655" height="321" class="alignnone size-full wp-image-1574" /></p>
<p>The correct answer is No. They&#8217;re not. If you look at the line height, the font size, almost everything you&#8217;ll find that these two paragraphs are exactly the same with the exception of the <code>&lt;code&gt;</code> tags in the second paragraph. Digging in deeper you&#8217;ll see the following problems with the paragraph height:</p>
<p><a href="http://media.paulrohde.com/blog/2011/11/ielh-2.png" rel="lightbox"><img src="http://media.paulrohde.com/blog/2011/11/ielh-2-300x154.png" alt="" title="ielh-2" width="300" height="154" class="alignleft size-medium wp-image-1575" /></a></p>
<p><a href="http://media.paulrohde.com/blog/2011/11/ielh-3.png" rel="lightbox"><img src="http://media.paulrohde.com/blog/2011/11/ielh-3-300x168.png" alt="" title="ielh-3" width="300" height="168" class="alignleft size-medium wp-image-1576" /></a><br />
<br style="clear: both" /></p>
<p><em>Four. Pixels. Taller.</em> <del>*explicitive*.</del> Most people wouldn&#8217;t care, or even notice unless you were using a baselineing tool like <a href="http://www.paulrohde.com/typesetter-hd/">Typesetter</a>. The solution, after much digging around, is to set the line height of <code>&lt;code&gt;</code> tags to zero.</p>
<pre class="css">&nbsp;
code <span style="color: #66cc66;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">line-height</span>: <span style="color: #933;">0</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p><img src="http://media.paulrohde.com/blog/2011/11/ielh-4.png" alt="" title="ielh-4" width="654" height="359" class="alignnone size-full wp-image-1577" /></p>
<p>And like magic, all of a sudden your paragraphs now behave correctly. This may be classified as a bug, at the very least, its an annoyance, but if you find yourself having problems with your paragraph line heights not behaving quite right, take a look and give this a shot.</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/21W6vVpeE50" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/invisible-extra-line-height/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/invisible-extra-line-height/</feedburner:origLink></item>
		<item>
		<title>Typesetter HD</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/IHAbwjeosG0/</link>
		<comments>http://www.paulrohde.com/typesetter-hd/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 00:00:59 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[baseline]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[typesetter]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1581</guid>
		<description><![CDATA[Just a quick heads up, I updated TypeSetter to work with high density displays. So if your on an iPhone 4 or 4S, or any other device that has a non standard pixel ratio and uses the baseline script it will show up clean and sharp. http://gist.github.com/1270673#file_type_setter.js Here&#8217;s a sample with the updated grid drawing [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick heads up, I updated TypeSetter to work with high density displays. So if your on an iPhone 4 or 4S, or any other device that has a non standard pixel ratio and uses the baseline script it will show up clean and sharp.</p>
<p><a href-"http://gist.github.com/1270673#file_type_setter.js">http://gist.github.com/1270673#file_type_setter.js</a></p>
<p>Here&#8217;s a sample with the updated grid drawing code:</p>
<p><img src="http://media.paulrohde.com/blog/2011/11/typesetterHD.png" alt="" title="typesetterHD" width="640" height="960" class="alignnone size-full wp-image-1582" /></p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/IHAbwjeosG0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/typesetter-hd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/typesetter-hd/</feedburner:origLink></item>
		<item>
		<title>Back to HTML – Tricky margins</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/r_qtPeo7BoE/</link>
		<comments>http://www.paulrohde.com/back-to-html-tricky-margins/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 23:00:58 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[Margining]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1559</guid>
		<description><![CDATA[HTML layout is weird. Half the time it makes sense, and the other half it makes half as much sense as it should. To that end, here&#8217;s a quick refresher on margins and padding and layout that I&#8217;m writing as much for myself as for you. Lets start with a box. In this imaginary real [...]]]></description>
			<content:encoded><![CDATA[<p>HTML layout is weird. Half the time it makes sense, and the other half it makes half as much sense as it should. To that end, here&#8217;s a quick refresher on margins and padding and layout that I&#8217;m writing as much for myself as for you.<br />
Lets start with a box. In this imaginary real box wold, you are either putting blocks next to each other, or inside other boxes, to get elements to line up and appear in some fashion or another. These virtual boxes have two properties, margin and padding. In our box world analogy, the padding would represent the thickness of the walls of the box. If you add something thats bigger than the inside of the box, the actual outside edge of the box will have too expand to contain whatever is inside. When you set a margin however, its simply stating a rule that you would like this box to be at least x number of units away from any other sibling box.</p>
<p>For instance, I have Box A and I want anything around Box A to be at least 2 feet away on the top or bottom of the box. Now, I have Box B that also has margin, but for Box B I only need everything to be 1 foot away along the top or bottom of the box. If I placed these two boxes next to each other (as siblings), the boxes would be 2 feet apart. Box A overrules Box B since A requests any other box to be further away from B, and thus B is also satisfied since the margin for B is less than A. If I also specified padding for box B of 6 inches, the contents of B would be at least 2 feet 6 inches from A since margin is measured from the outside edge of the box.</p>
<p>Here is a real example. In this case, I have 2 paragraphs. The orange space represents margins, and the green represents padding as shown by the debugging tools in chrome.</p>
<p>The code looks something like this:</p>
<pre>&nbsp;
&lt;article&gt;
     &lt;p&gt;This is some paragraph text 1&lt;/p&gt;
     &lt;p&gt;more paragraph text&lt;/p&gt;
&lt;/article&gt;
&nbsp;</pre>
<p>Example 1 Margining:</p>
<p><img src="http://media.paulrohde.com/blog/2011/11/tricky-margins-1.png" alt="" title="tricky-margins-1" width="328" height="116" class="alignnone size-full wp-image-1560" /><br />
<img src="http://media.paulrohde.com/blog/2011/11/tricky-margins-2.png" alt="" title="tricky-margins-2" width="283" height="123" class="alignnone size-full wp-image-1561" /></p>
<p>Notice how the margins collapse when they touch each other. Remember that margin represents &#8216;minimum spacing&#8217;.</p>
<p>Example 2 Padding:</p>
<p><img src="http://media.paulrohde.com/blog/2011/11/tricky-margins-3.png" alt="" title="tricky-margins-3" width="300" height="134" class="alignnone size-full wp-image-1562" /><br />
<img src="http://media.paulrohde.com/blog/2011/11/tricky-margins-4.png" alt="" title="tricky-margins-4" width="298" height="146" class="alignnone size-full wp-image-1563" /></p>
<p>Notice how not only are the paragraphs further apart with similar spacing, but they padding doesn&#8217;t overlap at all. This distinction is important when you lay out content, and especially when you start floating things. Eventually the imaginary real box model starts to break down as we approach real world HTML. Another really important tidbit to understand is that margining can extend OUTSIDE of the container. For instance, in the previous code snippet, we only have one article and two
<p> tags. If we put two articles side by side, we can see how the paragraph margining will extend out of the article block:</p>
<p>HTML:</p>
<pre>&nbsp;
&lt;article&gt;
     &lt;p&gt;This is some paragraph text 1&lt;/p&gt;
     &lt;p&gt;more paragraph text&lt;/p&gt;
&lt;/article&gt;
&lt;article&gt;
     &lt;p&gt;This is some paragraph text 1&lt;/p&gt;
     &lt;p&gt;more paragraph text&lt;/p&gt;
&lt;/article&gt;
&nbsp;</pre>
<p>Note how the article is only the size of the paragraphs inner dimensions:</p>
<p><img src="http://media.paulrohde.com/blog/2011/11/tricky-margins-5.png" alt="" title="tricky-margins-5" width="373" height="280" class="alignnone size-full wp-image-1564" /></p>
<p>However, when we look at the paragraph margining, we see:</p>
<p><img src="http://media.paulrohde.com/blog/2011/11/tricky-margins-6.png" alt="" title="tricky-margins-6" width="418" height="319" class="alignnone size-full wp-image-1565" /></p>
<p>The paragraph spacing extends beyond the bounds of the article and pushes the paragraphs and the article down. I know. The box model doesn&#8217;t work any more. Remember the differences and play around with it yourself.</p>
<h3>Some Practical Advice</h3>
<ul>
<li>When you first start laying elements out on a page, only specify bottom margining and keep the space consistent. It will help debug initial issues since there will be less overlapping margins.</li>
<li>Use a sylesheet language like less or sass so you can keep the numbers more consistent and easier to change.</li>
<li>Use good debugging tools. Chrome Developer tools, or Firebug are both good. They&#8217;ll keep you from going insane immediately.</li>
<li>If all else fails, simplify the problem. Make a small, quick html page to try to replicate your scenario.</li>
<li>Tinker. You only learn something by doing it. Do it.</li>
</ul>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/r_qtPeo7BoE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/back-to-html-tricky-margins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/back-to-html-tricky-margins/</feedburner:origLink></item>
		<item>
		<title>Tip: Using zoom to target images to high density displays</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/31ck6SHWgxQ/</link>
		<comments>http://www.paulrohde.com/tip-using-zoom-to-target-images-to-high-density-displays/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 23:00:36 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[iPhone 4]]></category>
		<category><![CDATA[iPhone 4S]]></category>
		<category><![CDATA[media queries]]></category>
		<category><![CDATA[Retina Display]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1553</guid>
		<description><![CDATA[I found this several days ago when I was looking for a way to scale images on an iPhone inside of a fluid layout such that they would display at a 1:1 pixel ratio. If you didn&#8217;t already know, the iPhone 4 and 4S displays everything as if the screen was the same size as [...]]]></description>
			<content:encoded><![CDATA[<p>I found this several days ago when I was looking for a way to scale images on an iPhone inside of a fluid layout such that they would display at a 1:1 pixel ratio. If you didn&#8217;t already know, the iPhone 4 and 4S displays everything as if the screen was the same size as a normal iPhone when it measures and does the layout. The result is that all the text looks extremely crisp, and any sites already designed for the original iPhone don&#8217;t break or look weird. With images this means that a 300 x 300 pixel image displays the correct size in the layout, but is essentially scaled up to fit over 600&#215;600 &#8220;physical pixels&#8221;. As I was poking around I found an old CSS zoom property here: <a href="http://reference.sitepoint.com/css/zoom">http://reference.sitepoint.com/css/zoom</a> that for some reason works on mobile safari. Add a media query for 2x density screens, and viola! Your images now display at physical pixel dimensions on the iPhone 4 and 4S.</p>
<p>Here&#8217;s what the CSS looks like:</p>
<pre language="css" >
@media screen and (-webkit-min-device-pixel-ratio: 2) {
     img {
          zoom: 50%;
     }
}
</pre>
<p>Awesome hacks.</p>
<p>Happy img scaling.</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/31ck6SHWgxQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/tip-using-zoom-to-target-images-to-high-density-displays/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/tip-using-zoom-to-target-images-to-high-density-displays/</feedburner:origLink></item>
		<item>
		<title>On Modern Layouts and Semi Fluid Grids</title>
		<link>http://feedproxy.google.com/~r/paulrohdecom/~3/y35uxr9qLb4/</link>
		<comments>http://www.paulrohde.com/on-modern-layouts-and-semi-fluid-grids/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 01:28:07 +0000</pubDate>
		<dc:creator>Paul Rohde</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Graphic Design]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[UX]]></category>

		<guid isPermaLink="false">http://www.paulrohde.com/?p=1548</guid>
		<description><![CDATA[Cross post: This article has been cross posted from http://blogs.interknowlogy.com/2011/10/25/on-modern-layouts-and-semi-fluid-grids/ Over the last several weeks, I&#8217;ve really been digging into HTML5, CSS3, and really figuring out what modern browsers can do. Frankly browsers have grown by leaps and bounds over the last several years, and as such we need to re-evaluate how we build websites. [...]]]></description>
			<content:encoded><![CDATA[<p><small>Cross post: This article has been cross posted from <a href="http://blogs.interknowlogy.com/2011/10/25/on-modern-layouts-and-semi-fluid-grids/">http://blogs.interknowlogy.com/2011/10/25/on-modern-layouts-and-semi-fluid-grids/</a></small></p>
<p>Over the last several weeks, I&#8217;ve really been digging into HTML5, CSS3, and really figuring out what modern browsers can do. Frankly browsers have grown by leaps and bounds over the last several years, and as such we need to re-evaluate how we build websites. Especially in regards to how we treat older browsers. I recently read <a href="http://paulirish.com/2011/tiered-adaptive-front-end-experiences/">this post by Paul Irish</a> and he points out that ideally, <strong>each browser gets an experience that is customized to that browser&#8217;s capabilities.</strong> What this <em>means</em> however, is that we should expect older browsers to get an experience that isn&#8217;t exactly the same as the experience we get on a modern one. (Example, no rounded corners. No text shadows. Etc&#8230;)</p>
<p>Let me try to explain:</p>
<p>A really good analogy to this is how HD TVs have changed the TV industry. Imagine for a moment that a website site is the film, and the TV is your browser. If you had a black and white TV, you wouldn&#8217;t expect to see the film in color. If you have a standard definition TV you don&#8217;t expect to see the full wide screen movies, and if you have a widescreen 720p TV, you don&#8217;t expect to experience the full effect of 1080p Blu-ray. Filmmakers don&#8217;t shoot in standard definition and then try to &#8216;upgrade&#8217; the film to HD quality. Its pointless and a LOT of extra work. No, they shoot with the best film and resolution they can afford and then cut it down to the lower denominators when or if they support older formats.</p>
<p>In the same way, if you use an older browser you wouldn&#8217;t expect to get the full experience a modern browser supplies, and moreover, you likely wouldn&#8217;t even know what your missing! You don&#8217;t expect it since any other site you visit also doesn&#8217;t have those features or details. Because of this, you should be designing for the &#8217;1080p&#8217; of the web, and accept that users with older browsers will still get the &#8216;standard definition&#8217; experience.</p>
<h3>The Web Is Not Print</h3>
<p>There&#8217;s also an important distinction between print and the web. The web is dynamic and fluid, highly interactive. The web is also delivered on a range of sizes and devices, from something the size of a business card up to large 30&#8243; monitors. There comes a point where form and function have to merge in a non-trivial way to provide an experience that fits itself to the users needs, when they need it, the way they need it.</p>
<p>Print isn&#8217;t.</p>
<p>Print is extremely static, once it&#8217;s designed, it stays that way. If you design a poster, you design it to be printed at a certain size or at certain proportions. If you design a book or a magazine, you have total control over the size and layout of your spread. If you continue to think about the web this way, you&#8217;ll miss much of the dynamic nature of the web that makes it attractive as a medium.</p>
<p>Its only recently we&#8217;ve really gained the tools and techniques we need to REALLY break out and away from the classic printers layout due largely to the rise in mobile devices, HTML5 and CSS3. What I&#8217;m calling this &#8220;Print Format&#8221; tends to reveal itself at the extreme edge cases.</p>
<p>Specifically:</p>
<ul>
<li>On large monitors where content will appear tiny and hard to read with lots of extra white space.</li>
<li>On small monitors or mobile devices when the content doesn&#8217;t scale down and your forced to scroll back and forth to read.</li>
</ul>
<p>Over the years one of the only real solutions to address this, if someone addressed it at all, was just to never set a width for your content and just let it fill your entire screen. Although this almost works for some things, it&#8217;s difficult to read as paragraphs will stretch across the screen. You will constantly lose your place as your eyes track back and forth to the beginning of the next line. Also, if your designing a static site and you and your designers both have large screens, it&#8217;s easy to &#8216;fill up the space&#8217; with ancillary or useless content and ads to make the site feel balanced. All in all, most so called solutions were hacks on a broken system.</p>
<h3>Semi Fluid Layout</h3>
<p>I&#8217;m finally starting to see some CSS frameworks and sites that are really starting to apply these principles. An excellent site that demonstrates this principle is the following:</p>
<p><a href="http://www.goldengridsystem.com/">www.goldengridsystem.com</a></p>
<p>No matter what browser you visit it on, or what size your browser is at, the content will be sized appropriately, the typography will be readable, and everything will <em>feel</em> right. Sans insane urges to resize your browser window.</p>
<p>One of the key benefits to designing a fluid theme is the instantly correct look you get when you open the site. Its not something people will or should consciously expect, it should simply BE the correct size the instant it appears, regardless of size, screen, or orientation. Its like walking into a store. A well designed building is easy to navigate, spacious, and consistent across all other stores you visit regardless of size. You don&#8217;t ever think about it, you&#8217;re not there to analyze the layout of the store. You&#8217;re there to buy groceries. Anything that gets in the way or makes it hard to find what you&#8217;re looking for will stick out, and if it&#8217;s bad enough, you&#8217;ll go somewhere else. Its the same way with a site or blog. Users are there for a reason: For information, or to read, or to consume whatever content you are serving up. They didn&#8217;t come to analyze your site and how it&#8217;s designed, but if they have any difficulty at all in getting to what they want in whatever form they want it in, they&#8217;ll be somewhere else in about 8 seconds.</p>
<p>It&#8217;s also important to be intentional about the decisions your making and how they will affect the final layout of a site. The more you reduce the complexity of the interactions, and the better defined the interactions are, the better the final end result will be. Use what you design. Do what your users do. You&#8217;ll know best what you do and don&#8217;t like and what <em>feels</em> right. Go with it, but don&#8217;t be afraid to stop, backtrack, or even completely scrap good ideas if they don&#8217;t fit with what you expect from the design.</p>
<h3>Fluid Layout First</h3>
<p>Something that&#8217;s going to become really important is to start out your design efforts knowing your designing for a fluid site like this. Laying out the groundwork and page structure is going to be extremely important to your long term sanity as a developer. There&#8217;s this concept in computer science called emergent behavior, essentially, the less you specify about a system, and by imposing fairly simple rules you can get easily get complex behavior. By starting with the containers, and then working your way to the content I have much less to worry about since most of the content takes care of itself without much more intervention from the developer.</p>
<p>If your someone who already has a well established, static width layout, its going to be difficult to establish a well behaved fluid grid system without tweaking MANY aspects of the site. Its probably why a lot of companies simply serve up an entirely different set of HTML and CSS for the site for mobile devices: Its easier to do than to rebuild their main site to scale all the way down to small screens.</p>
<img src="http://feeds.feedburner.com/~r/paulrohdecom/~4/y35uxr9qLb4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.paulrohde.com/on-modern-layouts-and-semi-fluid-grids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.paulrohde.com/on-modern-layouts-and-semi-fluid-grids/</feedburner:origLink></item>
	</channel>
</rss>

