<?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>Doctyper &#187; CSS</title>
	<atom:link href="http://doctyper.com/archives/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://doctyper.com</link>
	<description>Doctyper is the website of Richard Herrera, a front-end developer with a strong commitment to the web standards movement.</description>
	<lastBuildDate>Sat, 31 Jul 2010 00:17:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Substitute :last-child for :first-child for IE 7 support</title>
		<link>http://doctyper.com/archives/200912/substitute-last-child-for-first-child-for-ie-7-support/</link>
		<comments>http://doctyper.com/archives/200912/substitute-last-child-for-first-child-for-ie-7-support/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 23:05:29 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Quick Tip]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=56</guid>
		<description><![CDATA[Consider the following:
ul li {
&#160;&#160; display: inline;
&#160;&#160; margin-right: 10px;
&#160;&#160; padding-right: 10px;
&#160;&#160; border-right: 1px solid red;
}
ul li:last-child {
&#160;&#160; margin-right: 0;
&#160;&#160; padding-right: 0;
&#160;&#160; border-right: 0;
}
This bit of CSS would give you perfect line separators in IE8+. But since IE 7 supports the :first-child pseudo-class, we can do one better:
ul li {
&#160;&#160; display: inline;
&#160;&#160; margin-left: 10px;
&#160;&#160; padding-left: 10px;
&#160;&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Consider the following:</p>
<p><code>ul li {<br />
&nbsp;&nbsp; display: inline;<br />
&nbsp;&nbsp; margin-right: 10px;<br />
&nbsp;&nbsp; padding-right: 10px;<br />
&nbsp;&nbsp; border-right: 1px solid red;<br />
}</code></p>
<p><code>ul li:last-child {<br />
&nbsp;&nbsp; margin-right: 0;<br />
&nbsp;&nbsp; padding-right: 0;<br />
&nbsp;&nbsp; border-right: 0;<br />
}</code></p>
<p>This bit of CSS would give you perfect line separators in IE8+. But since IE 7 supports the :first-child pseudo-class, we can do one better:</p>
<p><code>ul li {<br />
&nbsp;&nbsp; display: inline;<br />
&nbsp;&nbsp; margin-left: 10px;<br />
&nbsp;&nbsp; padding-left: 10px;<br />
&nbsp;&nbsp; border-left: 1px solid red;<br />
}</code></p>
<p><code>ul li:first-child {<br />
&nbsp;&nbsp; margin-left: 0;<br />
&nbsp;&nbsp; padding-left: 0;<br />
&nbsp;&nbsp; border-left: 0;<br />
}</code></p>
<p>Same* result, with more browser support.<br />
<small>*Substitute for &#8220;sane&#8221;.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200912/substitute-last-child-for-first-child-for-ie-7-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RGBa makes a great debugging tool</title>
		<link>http://doctyper.com/archives/200912/rgba-makes-a-great-debugging-tool/</link>
		<comments>http://doctyper.com/archives/200912/rgba-makes-a-great-debugging-tool/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 22:31:09 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=48</guid>
		<description><![CDATA[With 24 Ways pushing RGBa into the foreground today, I thought I&#8217;d share a quick debugging tip. Using RGBa can help while you&#8217;re debugging element positioning. For the adventurous, combine with a debug class:
.debug {
&#160;&#160;background: rgba(255, 0, 0, 0.5);
}
]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://24ways.org/2009/working-with-rgba-colour">24 Ways</a> pushing RGBa into the foreground today, I thought I&#8217;d share a quick debugging tip. Using RGBa can help while you&#8217;re debugging element positioning. For the adventurous, combine with a debug class:</p>
<p><code>.debug {<br />
&nbsp;&nbsp;background: rgba(255, 0, 0, 0.5);<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200912/rgba-makes-a-great-debugging-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixed positioning in Mobile Safari</title>
		<link>http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/</link>
		<comments>http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 00:34:07 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=44</guid>
		<description><![CDATA[Update: An anonymous genius in the comments suggested using translateY instead of top for the animation. After some edits I&#8217;ve updated my demo, and it flies! The scrolling animation is smooth as silk. Apparently Webkit transforms are the only hardware-accelerated animations at this point. Thanks, random dude on the internet!
Update 2: This code is released [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> An anonymous genius in the comments suggested using translateY instead of top for the animation. After some edits I&#8217;ve updated my demo, and it flies! The scrolling animation is smooth as silk. Apparently Webkit transforms are the only hardware-accelerated animations at this point. Thanks, random dude on the internet!</p>
<p><strong>Update 2</strong>: This code is released to the public domain. You can use, modify, remix as you see fit.</p>
<p>Behold, fixed positioning on iPhone! <a href="http://doctyper.com/stuff/iphone/fixed/">http://doctyper.com/stuff/iphone/fixed/</a></p>
<p><a href="http://doctyper.com/stuff/iphone/fixed/fixed-positioning.mov">Here&#8217;s a video</a> for those without iPhones. This is running in the iPhone Simulator bundled with the SDK. Note that the animation is much choppier on an actual iPhone.</p>
<p>With the release of iPhone OS 2.0 came some great improvements over previous Mobile Safari versions. CSS animations are in (though buggy), as well as native touch events like touchstart, touchend, gesturechange, etc.</p>
<p>I played around with these new goodies while hunting for improvements to build into <a href="http://pickleview.com">Pickleview</a>. The most fascinating change to me was that you can now prevent the default behavior of elements with a simple preventDefault() call. It allows a user to drag an element around the screen without having to worry about the viewport wobbling about.</p>
<p>I grew curious as to what I could specifically call this on, and started testing out several elements. Turns out you can preventDefault on everything in the DOM, including the body element. This seemed incredibly useless for no other reason than the terrible usability it would bring if you couldn&#8217;t scroll the viewport. Then the proverbial light bulb went off: <em>fixed positioning</em>!</p>
<p>First, let&#8217;s recap why fixed positioning does not work off-the-bat. Mobile Safari uses a viewport to show you websites. Imagine a book in front of you. Take a piece of paper, cut a 320&#215;416 square in it, and lay it over the book. To read the book, move the paper around and position the hole over the words you want to see. This is exactly what Mobile Safari&#8217;s viewport is doing. When you flick and scroll, you&#8217;re moving the viewport around while the website behind it stays static.</p>
<p>This renders fixed positioning null and void on iPhone. An element that has its position fixed is affixed to the <em>body</em>, not the viewport. So it <em>is</em> actually working as intended, though most people would prefer it attached to the viewport.</p>
<p>There are workarounds in the wild, but these are inelegant. You can reposition an element onscroll, but a scroll event in Mobile Safari is only fired after scrolling has stopped. This results in an evident &#8220;glitch&#8221; since you have to a) flick to your desired position, throwing the element off-screen, and b) wait for the element to reappear in the viewport after scrolling has stopped.</p>
<p>By disabling the default scroll behavior on the body element, you essentially glue the viewport down to its initial starting point, where it&#8217;s unable to go anywhere. This limits the viewport to exactly 320&#215;416 pixels of space to show you. In this state, you have a perfectly useless experience.</p>
<p>This is where it gets interesting. In order to re-enable scrolling, I needed to only make the content area scrollable (think iframe, with header and footer above and below it). The touch and gesture events gives access to X/Y values, as well as timers and offset values. So by logging these and incrementing the top offset of the content area, we can create a scrollable block that does not affect the header or footer elements. A little spit and polish later: voila!</p>
<p>It&#8217;s pretty evident from my proof-of-concept that CSS animations need a lot of work. They&#8217;re promised to be &#8220;hardware-accelerated&#8221;, but there&#8217;s little proof of this. Most animations glitch, some to the point of non-use. The scrolling isn&#8217;t particularly smooth and even something as simple as animating a &#8216;top&#8217; CSS property takes its toll. Still it&#8217;s usable, though I hope later Mobile Safari builds will address these issues.</p>
<p>If you&#8217;re interested, I&#8217;ve bundled together the source files for my proof-of-concept. <a href="http://doctyper.com/stuff/iphone/fixed/fixed-positioning.zip">Grab &#8216;em here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/feed/</wfw:commentRss>
		<slash:comments>63</slash:comments>
<enclosure url="http://doctyper.com/stuff/iphone/fixed/fixed-positioning.mov" length="3815585" type="video/quicktime" />
		</item>
		<item>
		<title>Flow 1.0.2</title>
		<link>http://doctyper.com/archives/200807/flow-102/</link>
		<comments>http://doctyper.com/archives/200807/flow-102/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 19:19:52 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=41</guid>
		<description><![CDATA[I just pushed release 1.0.2 out the door.
Bug fix:
Flow will no longer choke with SWFObject.
Early this morning I received a report about Flow not playing nicely with SWFObject. After debugging, it turned out it was a case of doing too much.
SWFObject correctly cleans up after itself in IE by removing its generated code on unload. [...]]]></description>
			<content:encoded><![CDATA[<p>I just pushed release 1.0.2 out the door.</p>
<h4>Bug fix:</h4>
<p>Flow will no longer choke with SWFObject.</p>
<p>Early this morning I received a report about Flow not playing nicely with SWFObject. After debugging, it turned out it was a case of doing too much.</p>
<p>SWFObject correctly cleans up after itself in IE by removing its generated code on unload. The conflict appears because Flow does the same with its code, going as far as eliminating all extended element properties.</p>
<p>So when SWFObject tried to removeChild, it returned null because Flow extends that property, and by the time SWFObject got to it, it was already wiped out.</p>
<p>Flow now merely restores an extended property back to its original implementation, rather than nullifying the property. This will fix the error.</p>
<h4>Feature:</h4>
<p>dispatchEvent is now implemented in Flow. You can use it to fire events on elements from another element. Confusing? Here&#8217;s an example:</p>
<p><code>var test = document.getById(&quot;test&quot;);<br />
test.addEventListener(&quot;click&quot;, function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;// console.log(this.id);<br />
}, false);<br />
&nbsp;<br />
document.getById(&quot;dispatcher&quot;).addEventListener(&quot;click&quot;, function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;test.dispatchEvent(&quot;click&quot;);<br />
}, false);</code></p>
<p>You can pass any event type and it will fire all events coupled with that type.</p>
<p>As usual, you can download the Flow framework at <a href="http://flowjs.com">http://flowjs.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200807/flow-102/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pickleview 1.0</title>
		<link>http://doctyper.com/archives/200708/pickleview-10/</link>
		<comments>http://doctyper.com/archives/200708/pickleview-10/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 21:51:08 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://doctyper.com/archives/200708/pickleview-10/</guid>
		<description><![CDATA[I&#8217;m proud to announce that we&#8217;ve just crossed this significant milestone. After weeks of crunching bugs and rolling out update after update, Pickleview is officially a 1.0 release.
What started as a simple itch to scratch has turned into a full-fledged iPhone application, used by true honest-to-goodness people. Really!
The feedback has been nothing short of spectacular. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m proud to announce that we&#8217;ve just crossed this significant milestone. After weeks of crunching bugs and rolling out update after update, <a href="http://pickleview.com" title="Pickleview 1.0">Pickleview</a> is officially a 1.0 release.</p>
<p>What started as a simple itch to scratch has turned into a full-fledged iPhone application, used by true honest-to-goodness people. Really!</p>
<p>The feedback has been nothing short of spectacular. We&#8217;ve <a href="http://ajaxian.com/archives/iphone-update-pickleview-dojo-chat-iui-generation-and-more">received</a> <a href="http://www.joehewitt.com/blog/iui_monotony.php">tons</a> of <a href="http://applephoneshow.com/index.php/archives/649">praise</a> and we&#8217;ve listened to your feedback, sometimes pushing out updates within hours of suggestions. A gigantic thank you to everyone who pushed us to keep upping the ante.</p>
<p>An extra amount of thanks to <a href="http://mlb.mlb.com" title="Major League Baseball">Major League Baseball</a> and <a href="http://twitter.com" title="Twitter">Twitter</a>, the entities responsible for providing us data. Without them Pickleview would not exist.</p>
<p>To commemorate this milestone, I&#8217;m happy to say that we&#8217;re releasing the Pickleview code under the <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0  License</a>. You are free to learn from it, distribute and modify (as long as you share alike). <a href="http://svn.iphonewebdev.com/pickleview/">View the source here</a>. Thanks to the good folk at iPhoneWebDev for hosting our files. We&#8217;re hoping it becomes the repository for open-source iPhone web applications.</p>
<p>Lastly, stay tuned. We&#8217;ve got things in the works, gears are grinding, and overtime is being spent.</p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200708/pickleview-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pickleview</title>
		<link>http://doctyper.com/archives/200707/pickleview/</link>
		<comments>http://doctyper.com/archives/200707/pickleview/#comments</comments>
		<pubDate>Fri, 13 Jul 2007 04:47:39 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://doctyper.com/archives/200707/pickleview/</guid>
		<description><![CDATA[I want to talk a little bit about a side project that&#8217;s gleefully taken up most of my free time.
Over the weekend I attended iPhoneDevCamp, a gathering of web geeks from around the globe with one purpose: to create applications for iPhone.
I went into the event with little-to-no expectation of anything happening. It being my [...]]]></description>
			<content:encoded><![CDATA[<p>I want to talk a little bit about a <a href="http://pickleview.com">side project</a> that&#8217;s gleefully taken up most of my free time.</p>
<p>Over the weekend I attended <a href="http://barcamp.org/iphonedevcamp">iPhoneDevCamp</a>, a gathering of web geeks from around the globe with one purpose: to create applications for iPhone.</p>
<p>I went into the event with little-to-no expectation of anything happening. It being my first BarCamp I didn&#8217;t know the atmosphere, how we would mingle, etc.</p>
<p>What happened that weekend was something I won&#8217;t forget for some time. It was a great feeling to walk through the Adobe Town Hall and see energy popping from 300 minds at once. You could feel the electricity as people discovered loopholes and solved riddles that had puzzled iPhone developers since its release.</p>
<p>My story was rather interesting. After a canceled flight and barely making the 6:00pm start time (United: Never Again), I was sticking with my usual schtick: talk to no one, avoid eye contact. Twenty minutes in, I suddenly realized the magnitude of the event and was determined to talk to someone&#8211; <em>anyone</em>.</p>
<p>It was then I spotted a couple of individuals at a corner table, mingling away. I took a chance, and introduced myself. Ryan and Seto were their names. A short while later,  Estelle joined the small table, and we started brainstorming.</p>
<p>I&#8217;d been developing a small web app I dubbed LiveScore for a <a href="http://dodgers.cc">Dodgers&#8217; fan forum</a> that I run.  It gave real-time updates of Dodger scores, as well as some vital stats of each game. On a whim I opened up the app and showed it to the group. The gang really took to it, and from that point brainstorming focused around LiveScore.</p>
<p>Minutes later, we had a prototype: A web app/mashup that would combine live game tracking with the ability to chat along with friends on Twitter.</p>
<p>And so, <a href="http://pickleview.com">Pickleview</a> was born.</p>
<p>In the span of 36 hours, we four furiously coded together the required bytes to get the app off the ground, and wrapped it around a native-looking UI. It was thrilling to say the least, if not completely overwhelming. I don&#8217;t believe I&#8217;ve ever coded so much in so short a time.</p>
<p>We had our small moment in the sun, making some <a href="http://content.zdnet.com/2346-9595_22-93897-4.html">top ten lists</a> and being interviewed by the <a href="http://mercextra.com/video/2007/07/09/inside-the-iphone-devcamp/">San Jose Mercury Press</a>. But the real payoff was being able to release a very useful app for others to enjoy.</p>
<p>That, and comments that would make anyone jump for joy. Thanks again, <a href="http://joehewitt.com">Joe</a>.</p>
<p>Since the camp, we&#8217;ve been working hard to improve our little app that could. We&#8217;ve added features such as play-by-play, visual cues on score, balls/strikes tracking, and lots and lots of bug fixes. I have to say I&#8217;m enjoying the ride. All for an app I&#8217;m proud to be a part of.</p>
<p>I should reiterate that neither I nor Ryan nor Seto nor Estelle had ever met each other before Friday. It was a great experience to be able to accomplish so much with virtual strangers. Pickleview, however, is quickly making us closer acquaintances.</p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200707/pickleview/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cross-browser opacity</title>
		<link>http://doctyper.com/archives/200703/cross-browser-opacity/</link>
		<comments>http://doctyper.com/archives/200703/cross-browser-opacity/#comments</comments>
		<pubDate>Sat, 10 Mar 2007 18:00:44 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://doctyper.com/archives/200703/cross-browser-opacity/</guid>
		<description><![CDATA[With the rapid proliferation of IE 7, I think a closer look at cross-browser opacity is needed.
Please note that I&#8217;m not talking about image-based opacity, but rather opacity on any given element. There are articles on image opacity that are still relevant to today&#8217;s browsers.
The current favorite method is a combo opacity/filter fix to placate [...]]]></description>
			<content:encoded><![CDATA[<p>With the rapid proliferation of IE 7, I think a closer look at cross-browser opacity is needed.</p>
<p>Please note that I&#8217;m not talking about image-based opacity, but rather opacity on any given element. There are <a href="http://www.themaninblue.com/writing/perspective/2004/06/18/" title="The Man in Blue &gt; .PNG alpha transparency hack limitations">articles</a> on image opacity that are still relevant to today&#8217;s browsers.</p>
<p>The current favorite method is a combo opacity/filter fix to placate Gecko and Webkit browsers, as well as IE 6 and below. This involves setting a opacity value for browsers that support the spec, and hacking out an acceptable solution for browsers that don&#8217;t (read: &lt;IE6). The fix is outlined below:</p>
<p><code><br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opacity: 0.5;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-moz-opacity: 0.5;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&lt;!&#45;-[if lte IE 6]&gt;<br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter: alpha(opacity=50);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;&lt;![endif]&#45;-&gt;<br />
</code></p>
<p>As you can see, the code is quite verbose for what it is. Let&#8217;s take it step-by-step. The first style block contains the supported opacity properties for Safari and Opera (opacity), as well as Gecko-based Firefox and Camino (-moz-opacity).</p>
<p>The latter block is designed so that only Internet Explorer receives that code (in real-world application, this code would appear in a separate &#8220;&lt;IE 6 only&#8221; style sheet. The block contains a proprietary property called &#8220;filter&#8221;, supported by Microsoft browsers. This property is not approved by the W3C, and is therefore invalid. Thus the need to &#8220;hide&#8221; it from validators and place it in its own style sheet.</p>
<p>While the code is slightly complex, it has served its purpose. But with the evolving nature of the web, its status has changed since this method was concocted. New browsers have emerged, others have updated.  Essentially the web has changed enough that we must tweak this fix in order to get true cross-browser opacity. There are a few ways to handle this depending on your preference and whether or not you care about style sheet validation. Lets take a look, first at the browser changes, and at a couple of updated fixes:</p>
<h3>Internet Explorer 7</h3>
<p>Its characteristics are impressive. It supports quite a bit more W3C approved properties than it&#8217;s predecessor. However, the powers-that-be decided that it would not support the opacity properties&#8211; not yet, anyway.</p>
<p>On the other hand, IE 7 does still support the proprietary filter property. This means that IE 7 will respond to the same fix created for IE 6.</p>
<p>However, one of the many improvements IE 7 brings to the table is its native support for PNG transparency. This is an important point, as it allows us to devise a fix that will play better for those not interested in yet another conditional comment.</p>
<h3>Gecko-based browsers (Firefox, Camino)</h3>
<p>Gecko browsers support their own proprietary CSS property, the -moz-opacity property. However, it&#8217;s no longer necessary to declare this property, since current versions now include support for the standard opacity property.</p>
<p>So, given these bits of info, we&#8217;re left with the following cross-browser opacity methods:</p>
<h3>The single conditional comment fix</h3>
<p>The simplest method of all these is to simply remove the -moz-opacity property and open up the IE conditional comment to include IE 7. Example below:</p>
<p><code><br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opacity: 0.5;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&lt;!&#45;-[if lte IE 7]&gt;<br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter: alpha(opacity=50);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;#someOtherElement {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height: 1%;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;margin-left: -3px;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;&lt;![endif]&#45;-&gt;<br />
</code></p>
<p>While this is an easy solution, it is not often the best. For example, your CC was probably specified for IE 6 and below for a reason. Remember that IE 7 is much more standards-aware than previous IE incarnations, and probably does not need any of the hacks defined in the &lt;IE 6 stylesheet. Thus, you&#8217;d most likely have to do some more work hiding <em>those</em> hacks from IE 7.</p>
<h3>The multiple conditional comment fix</h3>
<p>Another method is to create another stylesheet, and wrap it around an IE 7 conditional comment:</p>
<p><code><br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opacity: 0.5;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&lt;!&#45;-[if lte IE 6]&gt;<br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter: alpha(opacity=50);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;#someOtherElement {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height: 1%;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;margin-left: -3px;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;&lt;![endif]&#45;-&gt;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&lt;!&#45;-[if IE 7]&gt;<br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter: alpha(opacity=50);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;&lt;![endif]&#45;-&gt;<br />
</code></p>
<p>This fix addresses the problems of the earlier fix, but creates additional markup, not to mention yet another stylesheet to maintain. If all the IE 7 stylesheet does is add opacity support, it would hardly be in your best interest to keep it around.</p>
<h3>The IE 7 filter fix</h3>
<p>There is another way to support IE 7, and that involves using an <a href="http://www.practicalecommerce.com/blogs/developers-diary/archives/55">IE 7 CSS</a> filter to target only that browser:</p>
<p><code><br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opacity: 0.5;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;*:first-child + html #element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter: alpha(opacity=50);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&lt;!&#45;-[if lte IE 6]&gt;<br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter: alpha(opacity=50);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;&lt;![endif]&#45;-&gt;<br />
</code></p>
<p>This works a treat, but it also carries the inconvenience of invalidating your style sheet.</p>
<h3>The PNG transparency fix</h3>
<p>This is my favorite method, merely because it eliminates the issues of the first three methods. However, that&#8217;s not to say it doesn&#8217;t come with it&#8217;s own flaws:</p>
<p><code><br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background: url(&quot;/path/to/image.png&quot;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&lt;!&#45;-[if lte IE 6]&gt;<br />
&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;#element {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter: alpha(opacity=50);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&lt;/style&gt;<br />
&nbsp;&nbsp;&lt;![endif]&#45;-&gt;<br />
</code></p>
<p>This method eliminates the opacity property altogether, and instead relies on a transparent PNG to mimic transparent color. Because IE 7 supports native PNG transparency, the fix works for all advanced browsers. The &lt;IE 6 stylesheet is left alone, since it&#8217;s PNG support leaves much to be desired.</p>
<p>The downside of this method, of course, is that you lose the ability to easily update the element you are editing. Rather than changing a hex value, or tweaking the opacity value, you&#8217;d have to go through your photo editor and change a PNG in order to see changes.</p>
<p>So there you have it, four distinct ways to implement cross-browser opacity. Each with its benefits, each with its flaws. It&#8217;s ultimately up to you to weigh those against each other, and choose what best fits your needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200703/cross-browser-opacity/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
