<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Markus Stange's Blog &#187; planet</title>
	<atom:link href="http://markusstange.wordpress.com/tag/planet/feed/" rel="self" type="application/rss+xml" />
	<link>http://markusstange.wordpress.com</link>
	<description></description>
	<lastBuildDate>Fri, 08 Mar 2013 11:20:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='markusstange.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Markus Stange's Blog &#187; planet</title>
		<link>http://markusstange.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://markusstange.wordpress.com/osd.xml" title="Markus Stange&#039;s Blog" />
	<atom:link rel='hub' href='http://markusstange.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Fun With Box Shadows</title>
		<link>http://markusstange.wordpress.com/2009/02/15/fun-with-box-shadows/</link>
		<comments>http://markusstange.wordpress.com/2009/02/15/fun-with-box-shadows/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 21:28:24 +0000</pubDate>
		<dc:creator>Markus Stange</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[planet]]></category>

		<guid isPermaLink="false">http://markusstange.wordpress.com/?p=11</guid>
		<description><![CDATA[In July 2008 Michael Ventnor implemented the CSS property box-shadow in Mozilla (as -moz-box-shadow, until the spec has stabilized). In this post I&#8217;d like to give a quick summary of how box shadows work. I&#8217;ve created a little demo page; all the shadows you see in this post are screenshots from that page. Use a [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markusstange.wordpress.com&#038;blog=6424017&#038;post=11&#038;subd=markusstange&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In July 2008 Michael Ventnor <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=212633" title="Bug 212633 - Add support for CSS3 box-shadow">implemented</a> the CSS property <code>box-shadow</code> in Mozilla (as <code>-moz-box-shadow</code>, until the <a title="CSS specification working draft" href="http://dev.w3.org/csswg/css3-background/#the-box-shadow">spec</a> has stabilized). In this post I&#8217;d like to give a quick summary of how box shadows work. I&#8217;ve created a little  <a href="http://tests.themasta.com/blogstuff/boxshadowdemo.html">demo page</a>; all the shadows you see in this post are screenshots from that page. Use a <a href="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/">recent nightly Firefox build</a> to view it.</p>
<h3>Overview</h3>
<p>The most basic way of setting a box shadow on a box is using <code>box-shadow: [x offset] [y offset] [color]</code>:</p>
<p><img src="http://markusstange.files.wordpress.com/2009/02/boxshadow001.png?w=164&#038;h=39" alt="" width="164" height="39" style="float:left;margin-bottom:10px;"><code>box-shadow: 5px 3px black;</code></p>
<p style="clear:left;">Adding another number lets you specify a blur radius:</p>
<p><img src="http://markusstange.files.wordpress.com/2009/02/boxshadow011.png?w=164&#038;h=46" alt="" width="164" height="46" style="float:left;margin-bottom:10px;"><code>box-shadow: 3px 3px <strong>5px</strong> black;</code></p>
<p style="clear:left;">You can even set a spread radius (this extends the shadow rect):</p>
<p><img src="http://markusstange.files.wordpress.com/2009/02/boxshadowspread.png?w=164&#038;h=50" alt="" width="164" height="50" style="float:left;margin-bottom:10px;"><code>box-shadow: 0 0 5px <strong>5px</strong> black;</code></p>
<p style="clear:left;">Negative spread values are possible, too:</p>
<p><img src="http://markusstange.files.wordpress.com/2009/02/negativespread1.png?w=164&#038;h=46" alt="" width="164" height="46" style="float:left;margin-bottom:10px;"><code>box-shadow: 0 5px 5px <strong>-3px</strong> black;</code></p>
<p style="clear:left;">Another interesting feature is the ability to set multiple box shadows, separated by comma, starting with the topmost shadow:</p>
<p><img src="http://markusstange.files.wordpress.com/2009/02/boxshadow031.png?w=164&#038;h=108" alt="" width="164" height="108" style="float:left;margin-bottom:10px;">
<pre><code>box-shadow:
  0 0 20px black,
  20px 15px 30px yellow,
  -20px 15px 30px lime,
  -20px -15px 30px blue,
  20px -15px 30px red;</code></pre>
<h3 style="clear:left;">Shadow Opacity</h3>
<p>What if you&#8217;d like the shadow to be more transparent? Just use the <code>rgba</code> syntax when setting the color and specify an appropriate alpha value:</p>
<p><img src="http://markusstange.files.wordpress.com/2009/02/boxshadow051.png?w=164&#038;h=45" alt="" width="164" height="45" style="float:left;margin-bottom:10px;"><code>box-shadow: 3px 3px 5px <strong>rgba(0, 0, 0, 0.5)</strong>;</code></p>
<p style="clear:left;">Increasing the opacity of a shadow is slightly more tricky. First you should try playing with the spread radius, but if that doesn&#8217;t give the right results, duplicating the shadow layer works, too:</p>
<p><img src="http://markusstange.files.wordpress.com/2009/02/boxshadow041.png?w=164&#038;h=46" alt="" width="164" height="46" style="float:left;margin-bottom:10px;"><code>box-shadow: <strong>3px 3px 5px black,</strong> 3px 3px 5px black;</code></p>
<h3 style="clear:left;">Inset Box Shadows</h3>
<p>Finally I&#8217;m getting to the reason I&#8217;m writing this blog post in the first place. Just over a week ago, Michael Ventnor <a title="Bug 476738 - Implement the 'inset' shadows part of the CSS3 box-shadow spec" href="https://bugzilla.mozilla.org/show_bug.cgi?id=476738">added support</a> for <em>inset</em> box shadows.</p>
<p>Using inset box shadows is as simple as adding the <code>inset</code> keyword to a box shadow layer.</p>
<p><img src="http://markusstange.files.wordpress.com/2009/02/inset00.png?w=164&#038;h=32" alt="" width="164" height="32" style="float:left;margin-bottom:10px;"><code>box-shadow: <strong>inset</strong> 2px 2px 5px black;</code></p>
<p style="clear:left;">Inset and outset shadows can be combined:</p>
<p><img src="http://markusstange.files.wordpress.com/2009/02/inset01.png?w=164&#038;h=43" alt="" width="164" height="43" style="float:left;margin-bottom:10px;"><code>box-shadow: inset 2px 2px 5px black, 2px 2px 5px black;</code></p>
<p style="clear:left;">Now the usefulness of multiple shadow layers becomes really apparent. You can use inset box shadows to create gradients, highlights, 3D borders etc. and freely stack them on top of each other. It&#8217;s just like using an unlimited number of &#8220;inner shadow&#8221; layer styles in Photoshop!</p>
<p>In combination with <a href="https://developer.mozilla.org/en/CSS/-moz-border-radius">border-radius</a> (which can even be <a href="http://dev.w3.org/csswg/css3-background/#the-border-radius">elliptical</a> in Firefox 3.5), the possibilities for creating shiny, image-less buttons are endless. For example, this is a recreated version of the button on <a href="http://getmiro.com/">getmiro.com</a>:</p>
<p><img src="http://markusstange.files.wordpress.com/2009/02/getmiro1.png?w=238&#038;h=50" alt="" width="238" height="50"> <img src="http://markusstange.files.wordpress.com/2009/02/getmiro2.png?w=238&#038;h=50" alt="" width="238" height="50"></p>
<p>The CSS code for buttons like this one can quickly become complicated, though&#8230; it&#8217;s all on the <a href="http://tests.themasta.com/blogstuff/boxshadowdemo.html">demo page</a>, in case you&#8217;re interested.</p>
<h3>More Examples</h3>
<p>Recreating Cocoa controls with box shadow (and without any images) is fun, too:</p>
<table>
<tr>
<td>Searchfields:</td>
<td><img src="http://markusstange.files.wordpress.com/2009/02/searchfields.png?w=260&#038;h=31" width="260" height="31"></td>
</tr>
<tr>
<td>Aqua buttons:</td>
<td><img src="http://markusstange.files.wordpress.com/2009/02/button1.png?w=74&#038;h=26" width="74" height="26"><img src="http://markusstange.files.wordpress.com/2009/02/button2.png?w=74&#038;h=26" width="74" height="26"></td>
</tr>
<tr>
<td>&#8220;Recessed&#8221; Cocoa buttons:</td>
<td><img src="http://markusstange.files.wordpress.com/2009/02/recessed.png?w=234&#038;h=26" width="234" height="26"></td>
</tr>
<tr>
<td>&#8220;Round textured&#8221; Cocoa buttons:</td>
<td><img src="http://markusstange.files.wordpress.com/2009/02/roundtextured.png?w=146&#038;h=31" width="146" height="31"></td>
</tr>
</table>
<h3>Adapting To The Background Color</h3>
<p>Inset box shadows are painted on top of the background layer. Black inset shadows make the background darker, white shadows make it lighter. If you keep that in mind, you can build box shadow constructs that can adapt to arbitrary backgrounds. I experimented a little and came up with super glossy boxes that look a little like Cocoa select boxes:</p>
<p><a href="http://tests.themasta.com/blogstuff/boxshadowselect.html"><img src="http://markusstange.files.wordpress.com/2009/02/select1.png?w=321&#038;h=212" alt="" width="321" height="212"></a></p>
<p>(See how the saturation is higher in the lower half of each box? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  )</p>
<h3>Browser Support</h3>
<p>As far as I know, Webkit was the first engine to implement support for box shadows. A basic form has been supported since the version that Safari 3 ships with, and support for <a href="https://bugs.webkit.org/show_bug.cgi?id=27417">spread radii</a> and <a href="https://bugs.webkit.org/show_bug.cgi?id=27582">inset box shadows</a> was added in July 2009. Consequently, recent versions of Chrome can do all these things, too. In Webkit the property is called <code>-webkit-box-shadow</code>.</p>
<p>Firefox supports box shadows starting with version 3.5 under the name <code>-moz-box-shadow</code>.</p>
<p>Good news for Opera users: The recently released <a href="http://my.opera.com/ODIN/blog/opera-10-5-pre-alpha-build-released-here-is-whats-new">Opera 10.5 pre-alpha</a> now supports box shadows, too! There are still some obvious bugs (e.g. box shadows with a zero blur radius sometimes aren&#8217;t painted), but I&#8217;m sure they&#8217;ll get fixed in time for the final release.<br />
It&#8217;s interesting to note that Opera doesn&#8217;t use a vendor prefix in their <code>box-shadow</code> property name. Webkit also did this at some point but later <a href="https://bugs.webkit.org/show_bug.cgi?id=29927" title="Webkit Bug 29927 - Re-add a vendor prefix to box-shadow">re-introduced the <code>-webkit-</code> prefix</a> since the box shadow section <a href="http://www.w3.org/blog/CSS/2009/10/01/resolutions_79">has been removed</a> from the <a href="http://dev.w3.org/csswg/css3-background/#the-box-shadow">CSS 3 Backgrounds and Borders specification</a>.</p>
<h3>Notes</h3>
<p>You should keep in mind that box shadows are rendered on the fly whenever your boxes are repainted. <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=458031">Some</a> <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=468018">performance</a> <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=475877">improvements</a> have already been made, but drawing box shadows is still expensive. So if you value rendering speed and need shadows for large boxes (or shadows with large blur values), you should definitely consider using images of &#8220;pre-computed&#8221; shadows instead (for example as <a href="https://developer.mozilla.org/En/CSS/-moz-border-image">border-images</a>).</p>
<p>Finally, I&#8217;d like to thank Michael for implementing this stuff in Firefox, and <a href="http://dbaron.org/">David Baron</a> and <a href="http://weblogs.mozillazine.org/roc/">Robert O&#8217;Callahan</a> for reviewing his patches &#8211; thanks!</p>
<p><em>Update 2009-04-08: dbaron approved the inset box shadow patch for 1.9.1 after all, and <a href="http://hg.mozilla.org/releases/mozilla-1.9.1/rev/cfea33167281">today I landed it</a> &#8211; that means we&#8217;ll get inset box shadows in Firefox 3.5! I&#8217;ve updated the article accordingly.</em></p>
<p><em>Update 2010-01-21: Updated the browser compatibility section since Webkit and the new Opera pre-alpha now support box-shadows.</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/markusstange.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/markusstange.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=markusstange.wordpress.com&#038;blog=6424017&#038;post=11&#038;subd=markusstange&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://markusstange.wordpress.com/2009/02/15/fun-with-box-shadows/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/9614f5290002968edd95bc04ad9cb9a9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Markus Stange</media:title>
		</media:content>

		<media:content url="http://markusstange.files.wordpress.com/2009/02/boxshadow001.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/boxshadow011.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/boxshadowspread.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/negativespread1.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/boxshadow031.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/boxshadow051.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/boxshadow041.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/inset00.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/inset01.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/getmiro1.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/getmiro2.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/searchfields.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/button1.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/button2.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/recessed.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/roundtextured.png" medium="image" />

		<media:content url="http://markusstange.files.wordpress.com/2009/02/select1.png" medium="image" />
	</item>
	</channel>
</rss>