<?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>Less code, more sleep &#187; Styling</title>
	<atom:link href="http://emmett.be/thewebdev/topics/frontend/styling/feed" rel="self" type="application/rss+xml" />
	<link>http://emmett.be/thewebdev</link>
	<description>Tales of an insomniac coder</description>
	<lastBuildDate>Mon, 26 Jul 2010 22:48:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Resize-to-window web apps</title>
		<link>http://emmett.be/thewebdev/archives/93</link>
		<comments>http://emmett.be/thewebdev/archives/93#comments</comments>
		<pubDate>Tue, 04 May 2010 20:07:17 +0000</pubDate>
		<dc:creator>Emmett Pickerel</dc:creator>
				<category><![CDATA[Frontend]]></category>
		<category><![CDATA[Styling]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Flash-like UI]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://emmett.be/thewebdev/?p=93</guid>
		<description><![CDATA[One of the things Flash designers have had which web developers have not is the ability to retarget an application to any viewport size desired. I&#8217;ve been saddled with implementing a by such a Flash designer for deployment in HTML/CSS/JS on QTwebkit. What&#8217;s amazing is that I&#8217;ve had some degree of success with it. I ]]></description>
			<content:encoded><![CDATA[<p>One of the things Flash designers have had which web developers have not is the ability to retarget an application to any viewport size desired. I&#8217;ve been saddled with implementing a by such a Flash designer for deployment in HTML/CSS/JS on QTwebkit.</p>
<p>What&#8217;s amazing is that I&#8217;ve had some degree of success with it. I can&#8217;t show a demo yet, but imagine that a fully animated, complicated application smoothly scales, centres, and otherwise behaves more or less like you&#8217;d expect Flash to.</p>
<p>To be sure, there are some sketchy areas. Webkit&#8217;s positioning math can be very sloppy if you need precision (my design does). Any container that&#8217;s affected by font size is going to change a little (not always bad).</p>
<p>Watch here for a demonstration of this soon, along with a bit of how-to.</p>
]]></content:encoded>
			<wfw:commentRss>http://emmett.be/thewebdev/archives/93/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chrome Quarters: a lightweight alternative to sliding doors.</title>
		<link>http://emmett.be/thewebdev/archives/4</link>
		<comments>http://emmett.be/thewebdev/archives/4#comments</comments>
		<pubDate>Fri, 13 Feb 2009 01:41:48 +0000</pubDate>
		<dc:creator>Emmett Pickerel</dc:creator>
				<category><![CDATA[Markup]]></category>
		<category><![CDATA[Styling]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[semantic markup]]></category>
		<category><![CDATA[sliding doors]]></category>

		<guid isPermaLink="false">http://emmett.be/thewebdev/?p=4</guid>
		<description><![CDATA[In an ideal world, HTML would mark up a document in a completely semantic way, with no extra nesting or non-semantic elements. There&#8217;s a very big stigma against use of &#8220;chrome-only&#8221; chunks of markup. I&#8217;d like to make the case that sometimes, such markup is, if not ideal, at least better than more popular alternatives. ]]></description>
			<content:encoded><![CDATA[<p>In an ideal world, HTML would mark up a document in a completely semantic way, with no extra nesting or non-semantic elements. There&#8217;s a very big stigma against use of &#8220;chrome-only&#8221; chunks of markup. I&#8217;d like to make the case that sometimes, such markup is, if not ideal, at least better than more popular alternatives.</p>
<p>Say you wanted a dynamically sized box to have nice borders with beveled or rounded 3D corners. Here&#8217;s the lightweight markup you start with (39 chars without content):</p>
<pre class="code html">&lt;div id="mybox"&gt;
  &lt;p&gt;Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
 doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
 veritatis et quasi architecto beatae vitae dicta sunt explicabo.&lt;/p&gt;
  &lt;p&gt;Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit.&lt;/p&gt;
&lt;/div&gt;</pre>
<p>You want to have that look something like this:</p>
<div id="attachment_9" class="wp-caption alignnone" style="width: 261px"><img class="size-full wp-image-9" title="Rounded corner box" src="http://emmett.be/thewebdev/wp-content/uploads/2009/02/picture-3.png" alt="Box with rounded corners, beveling and a gradient" width="251" height="223" /><p class="wp-caption-text">Box with rounded corners, beveling and a gradient</p></div>
<p>Unfortunately, CSS doesn&#8217;t give us any way to do that without specifying an exact height and width for the box &#8212; a major accessibility block. We need a nested container and a fake header (I&#8217;ll use the Yahoo! standard container model) in order to use the <a href="http://www.alistapart.com/articles/slidingdoors/" target="_blank">sliding doors</a> technique in 147 chars without content:</p>
<pre class="code html">&lt;div id="mybox"&gt;
  &lt;div class="hd"&gt;&lt;h4&gt;&lt;/h4&gt;&lt;/div&gt;
  &lt;div class="bd"&gt;
    &lt;div class="wrap"&gt;
      &lt;div class="wrap"&gt;
        &lt;p&gt;...&lt;/p&gt;
        &lt;p&gt;...&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;</pre>
<p>Now we can reach that style (with an appropriately large image). I won&#8217;t go into details on how to make CSS sliding doors, as that&#8217;s well documented elsewhere. Here&#8217;s what the CSS for that might look like:</p>
<pre class="code css">#mybox {
  max-width: 250px;
}
#mybox .hd, #mybox .hd h4, #mybox .bd, #mybox .bd .wrap {
  background: url(roundedCornerBoxBg1.png) no-repeat;
}
#mybox .hd {
  padding-left: 10px;
  margin-right: 10px;
}
#mybox .hd h4 {
  background-position: top right;
  height: 31px;
  margin: 0 -10px 0 0;
}
#mybox .bd {
  background-position: bottom left;
  padding-left: 10px;
  margin-right: 10px;
}
#mybox .bd .wrap {
  background-position: bottom right;
  margin-right: -10px;
}
#mybox .bd .wrap .wrap {
  background: none;
  position: relative;
  top: -24px;
  padding: 1px 0 0 1px;
  margin-right: 0;
}</pre>
<p>There are two markup problems with this: one, we&#8217;ve created non-semantic markup that <em>looks</em> semantic, and we&#8217;ve had to add three layers of nesting! How is this better than tables?</p>
<p>Even with all that, due to the 31px height that the chrome image has for the top gradient, we have to resort to negative margins for the innermost content wrapper to achieve centering of the content. Our content formatting CSS and chrome CSS are heavily intertwined. Even with that, we still have a large amount of padding on top and bottom that cannot be eliminated.</p>
<div id="attachment_10" class="wp-caption alignnone" style="width: 260px"><img class="size-full wp-image-10" title="Nested markup rendered" src="http://emmett.be/thewebdev/wp-content/uploads/2009/02/picture-2.png" alt="Nested markup rendered - lots of padding at top and bottom" width="250" height="238" /><p class="wp-caption-text">Nested markup rendered - lots of padding at top and bottom</p></div>
<h4>Another way: Chrome Quarters</h4>
<p>Consider this markup instead (142 characters without content, and chrome whitespace removed):</p>
<pre class="code html">&lt;div id="mybox"&gt;
  &lt;p&gt;Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
veritatis et quasi architecto beatae vitae dicta sunt explicabo.&lt;/p&gt;
  &lt;p&gt;Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit.&lt;/p&gt;
  &lt;b class="chr4c chrome"&gt;
    &lt;b class="ul"&gt;&lt;/b&gt;
    &lt;b class="ur"&gt;&lt;/b&gt;
    &lt;b class="lr"&gt;&lt;/b&gt;
    &lt;b class="ll"&gt;&lt;/b&gt;
  &lt;/b&gt;
&lt;/div&gt;</pre>
<p>Here, we&#8217;ve got a separate heirarchy just to hold the chrome, clearly marked as such. The chrome and content markup don&#8217;t interfere with one another. Here&#8217;s the CSS:</p>
<pre class="code css">.chr4c {
  display: none;
}
.chr4c * {
  display: block;
  position: absolute;
}
.chr4c .ul {
  background-position: left top;
  top: 0;
  right: 50%;
  bottom: 50%;
  left: 0;
}
.chr4c .ur {
  background-position: right top;
  top: 0;
  right: 0;
  bottom: 50%;
  left: 49%;
}
.chr4c .lr {
  background-position: right bottom;
  top: 49%;
  right: 0;
  bottom: 0;
  left: 49%;
}
.chr4c .ll {
  background-position: left bottom;
  top: 49%;
  right: 50%;
  bottom: 0;
  left: 0;
}
#mybox {
  max-width: 230px;
  min-height: 62px;
  position: relative;
  padding: 1px 10px;
}
#mybox .chr4c {
  display: block;
}
#mybox .chr4c * {
  z-index: -1;
  background-image: url(roundedCornerBoxBg1.png);
}
@media audio, speech {
  .chrome {
    display: none !important;
  }
}</pre>
<p>Here, our content formatting CSS is limited to a single rule, almost entirely separate from the chrome styling. A slate of generic rules sets up most of the styling for re-use in many rounded-corner type situations. The four corner pieces are positioned absolutely to occupy 1/4 of the box each (a small amount of overlap allows for IEEE floating point math oddities). The main container is set to <code class="css">position:relative</code> to constrain the absolutely positioned elements.</p>
<div id="attachment_13" class="wp-caption alignnone" style="width: 268px"><img class="size-full wp-image-13" title="Drawn and quartered" src="http://emmett.be/thewebdev/wp-content/uploads/2009/02/picture-42.png" alt="Finished box with chrome divided into four more-or-less equal quarters of the container." width="258" height="231" /><p class="wp-caption-text">Finished box with chrome divided into four more-or-less equal quarters of the container. Borders drawn for clarity.</p></div>
<p>The last rule hides all chrome-only elements from audio browsers, just to be on the safe side. They generally wouldn&#8217;t report empty spans, but this assures as much. The <code class="html">b</code> tag is used for brevity, and shouldn&#8217;t cause any more trouble than a <code class="html">span</code>.</p>
<h4>Browser bugs</h4>
<p>The one caveat I must offer: browsers sometimes have some odd rendering differences when it comes to the use of positioning within certain elements. <code class="html">div</code>s will generally work flawlessly, but you&#8217;ll find that browser differences abound when it comes to positioning inside <code class="html">button</code>s and <code class="html">li</code>s. In those cases, know that you&#8217;ll likely need to deliver different styles to various browsers.</p>
<p>Despite those limitations, I think you&#8217;ll agree that our finished markup and CSS is far more readable, maintainable and reusable than the first. Thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://emmett.be/thewebdev/archives/4/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
