<?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>piddmedia &#187; alpha</title>
	<atom:link href="http://piddmedia.com/tag/alpha/feed/" rel="self" type="application/rss+xml" />
	<link>http://piddmedia.com</link>
	<description>interactive design and development</description>
	<lastBuildDate>Mon, 28 Nov 2011 19:42:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Cross-Browser Opacity that Stops Inheritance</title>
		<link>http://piddmedia.com/tutorials/cross-browser-opacity-that-stops-inheritance/</link>
		<comments>http://piddmedia.com/tutorials/cross-browser-opacity-that-stops-inheritance/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 23:54:24 +0000</pubDate>
		<dc:creator>C. Scott Asbach</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[alpha]]></category>
		<category><![CDATA[cross-browser]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[graceful degradation]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[opacity]]></category>
		<category><![CDATA[rgb]]></category>
		<category><![CDATA[rgba]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://piddmedia.com/?p=425</guid>
		<description><![CDATA[Luckily we now have rgba() in modern standards compliant browsers (read not Internet Explorer).  Not only does rgba() allow you to create transparent backgrounds without passing inheritance, but it allows you to declare it on a single css property instead of setting the entire element to one level of opacity. No inheritance AND more granular control, what's not to love? <a href="http://piddmedia.com/tutorials/cross-browser-opacity-that-stops-inheritance/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<img width="550" height="196" src="http://piddmedia.com/wp-content/uploads/2010/03/opacity-550x196.jpg" class="attachment-single-post-thumbnail wp-post-image" alt="opacity" title="opacity" /><h3>The Skinny</h3>
<p>So if you know what you are doing and are just curious to see my solution here is the CSS that does what the title of this article claims:</p>
<pre class="brush: css; title: ; notranslate">
.startOpacity{
    background:rgb(255,255,255);
    background:rgba(255,255,255,0.7);
    -ms-filter:alpha(opacity=70);
    filter:alpha(opacity=70)
}
.stopOpacity{
    position:relative
}
</pre>
<p><span id="more-425"></span></p>
<p>As you can see the simple answer is: don&#8217;t use opacity when you can use rgba() instead. As for IE, this is one of those situations where its non-standard CSS implementation comes to the rescue.  Just add .stopOpacity (or position:relative) to the child of the element that has opacity whom you wish not to inherit opacity.  All opacity inheritance will stop with that child if you are using IE.  If you produce a browser that is not IE and also does not understand rgba() then this CSS will produce an element that has no opacity.  If you do not allow this degradation to adversely affect accessibility then we can call it graceful.</p>
<h3>What you Were Using</h3>
<p>So if you&#8217;ve used opacity in the past and wanted it to be as cross-browser compatible as possible, you were probably using this:</p>
<pre class="brush: css; title: ; notranslate">
.opacity{
    opacity: .75;
    filter: alpha(opacity=75);
    -ms-filter: &quot;alpha(opacity=75)&quot;;
    -khtml-opacity: .75;
    -moz-opacity: .75
}
</pre>
<p>It could be said that neither solution is very elegant.  This rule does the trick but for me it just didn&#8217;t quite hit the mark because of inheritance.  Every element that is nested inside an element with this CSS style will also have transparency.  I would venture to say that in most situations this is NOT desired.  Unfortunately the W3C disagrees so we have a spec that says opacity should be inherited.</p>
<h3>Enter rgba()</h3>
<p>Luckily we now have rgba() in modern standards compliant browsers (read not Internet Explorer).  Not only does rgba() allow you to create transparent backgrounds without passing inheritance, but it allows you to declare it on a single CSS property instead of setting the entire element to one level of opacity. No inheritance AND more granular control, what&#8217;s not to love?</p>
<h3>IE &#8211; Always the Downer</h3>
<p>With IE we have no choice but to keep doing things the old way.  However, we can use its own weapon of maddeningly random non-compliance against it!  If you add position:relative to a child of an element that has transparency, that child will no longer inherit that transparency.</p>
<h3><del datetime="2010-03-04T23:05:54+00:00">Hacking it Together</del> <ins datetime="2010-03-04T23:38:02+00:00">Reconciling with IE</ins></h3>
<p><strong>So how do we trick IE into ignoring rgba()?</strong></p>
<p>We don&#8217;t have to IE can&#8217;t read it.  Just declare an rgb() color first for IE to read, everyone else will overwrite it with the rgba() color &#8211; but only if it comes AFTER the rgb() color.</p>
<p><strong>What about the alpha filter?</strong></p>
<p>The filter property is only read by IE so there&#8217;s no need to hack anything there either.</p>
<p><strong>What&#8217;s the catch then?</strong></p>
<p>Well, there is one part that might be called a hack by some and that is the need to use the position:relative declaration on the children that you don&#8217;t want to inherit transparency in IE.  This is one of those declarations that really shouldn&#8217;t affect the style in the first place but just happens to fix an undesired effect in IE.  In situations like those the most I do is quarantine the rule in an IE style sheet.(linked with conditional comments)But even that isn&#8217;t really necessary.  By the way, if for some reason you require position:absolute or any other valid position: value it will still work.</p>
<h3>The Ugly Alternative</h3>
<p>The most popular alternative method for getting out of the transparency inheritance issue is to use absolutely positioned divs to place elements above a transparent element without those divs actually being nested inside the transparent element.  This is NOT good semantics and will add bloat to your mark-up.  The situation will dictate the proper solution though, for example <del datetime="2010-08-11T17:53:15+00:00">this is how I already position my navigation and banner ads for SEO purposes so I can take advantage of that</del> <ins datetime="2010-08-11T17:53:15+00:00"> I use a different theme now so you would see that this is no longer true, but the point remains valid. </ins> I cannot however, justify using AP divs solely to accommodate a hacky design.</p>
<p>That concludes this tutorial on stopping opacity inheritance. I hope this method improves your designs as  much as it has mine.</p>
<p><a style="display:none" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=7779576" rel="tag">CodeProject</a></p>
]]></content:encoded>
			<wfw:commentRss>http://piddmedia.com/tutorials/cross-browser-opacity-that-stops-inheritance/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

