<?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>Citizensheep &#187; Birmingham creative organisations</title>
	<atom:link href="http://citizensheep.com/blog/category/birmingham-creative-organisations/feed/" rel="self" type="application/rss+xml" />
	<link>http://citizensheep.com/blog</link>
	<description>Michael Grimes lives in Birmingham (UK). This is his blog about anything that he fancies.</description>
	<lastBuildDate>Sun, 05 Feb 2012 23:40:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using CSS to add opaque text to transparent backgrounds</title>
		<link>http://citizensheep.com/blog/2007/08/20/transparent-backgrounds-to-text/</link>
		<comments>http://citizensheep.com/blog/2007/08/20/transparent-backgrounds-to-text/#comments</comments>
		<pubDate>Mon, 20 Aug 2007 18:21:59 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Voluntary Sector]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[webdesign]]></category>

		<guid isPermaLink="false">http://citizensheep.com/blog/?p=23</guid>
		<description><![CDATA[CSS doesn&#8217;t currently allow for an element to have a transparent background with opaque text: the text will also be transparent. On top of that, any child elements will inherit the transparency. But there are ways… I&#8217;ve just redesigned this blog (come on, it could be worse), and I wanted the title to sit in [...]<ul id="related_posts">
			<li>
					<h4>Possibly related posts</h4>
				 <ol>
								<li>
									<a href="http://citizensheep.com/blog/2009/03/23/playing-with-css3-ie7-fails-of-course/" rel="bookmark">Playing with CSS (IE7 fails, of course)</a><!-- (30.9)-->
							</li>
								<li>
									<a href="http://citizensheep.com/blog/2007/09/10/css-sliding-doors-positioning-the-tabs/" rel="bookmark">CSS ‘sliding doors’: positioning the tabs</a><!-- (17.6)-->
							</li>
								<li>
									<a href="http://citizensheep.com/blog/2010/05/17/scratching-my-head-over-rails/" rel="bookmark">Scratching my head over Rails</a><!-- (5.7)-->
							</li>
					</ol>
			</li>
	</ul>]]></description>
			<content:encoded><![CDATA[<p>CSS doesn&#8217;t currently allow for an element to have a transparent background with opaque text: the text will also be transparent. On top of that, any child elements will inherit the transparency. But there are ways…</p>
<p>I&#8217;ve just redesigned this blog (come on, it could be worse), and I wanted the title to sit in a box on top of the image, and for the image to show through the background of the box; thus:</p>
<p><a title="Image showing transparent background to opaque text." href="http://citizensheep.com/blog/wp-content/uploads/2007/08/example_transpdivs.jpg"><img src="http://citizensheep.com/blog/wp-content/uploads/2007/08/example_transpdivs.jpg" alt="Image showing transparent background to opaque text." /></a></p>
<p>I did this using css positioning:</p>
<ol>
<li> I put the image in a div, and absolutely positioned the div at the top of the page;</li>
<li>I then created two identical versions of the title box, and absolutely positioned one over the top of the other:</li>
<li>the top one (<em>title</em>) has the text, with no opacity set;</li>
<li>the bottom one (<em>titleBox</em>) has a background colour with the opacity set to a degree of transparency; the text is also in this div, to ensure the box size matches that of the upper div. The text is hidden behind that of the upper div.</li>
</ol>
<p>However, what if I also wanted to add another div below these? At the moment it would have to be positioned absolutely, meaning that any resizing of the text could upset the flow of the document. My solution was:</p>
<ol>
<li>Put both divs into one new div (<em>topRight</em>);</li>
<li>Div <em>titleBox</em> comes first (though I guess it doesn&#8217;t matter if you add a z-index), with the default relative positioning;</li>
<li>Div <em>title</em> come next, positioned absolutely at the top (ie of div <em>topRight</em>).</li>
</ol>
<p>Now any new content will flow as expected, relative to the div <em>titleBox</em>.</p>
<p>Here&#8217;s the css (trimmed down for the sake of clarity):</p>
<ul class="code">
<li>#topRight {</li>
<li>position:absolute;</li>
<li>top:30px;</li>
<li>right:0;</li>
<li>}</li>
</ul>
<ul class="code">
<li>#title, #titleBox {</li>
<li>margin:0;</li>
<li>padding:10px;</li>
<li>}</li>
</ul>
<ul class="code">
<li>#titleBox {</li>
<li>opacity:0.2;</li>
<li>color:#fff;</li>
<li>}</li>
</ul>
<ul class="code">
<li>#title {</li>
<li>background:none;</li>
<li>z-index:1;</li>
<li>position:absolute;</li>
<li>top:0;</li>
<li>}</li>
</ul>
<p>Opacity appears to be supported by most browsers now (with the usual notable exception of Internet Explorer), though I haven&#8217;t tested extensively. I have also since added <a title="CSS3 info: border-radius." href="http://www.css3.info/preview/rounded-border.html">rounded corners</a>, but these are only visible in Firefox and Safari (using proprietary tags, while the rest of the browsers catch up).</p>
<h4>Update (March 2009)</h4>
<p>There is now growing support for RGBa, which enables the addition of alpha transparency to a colour. Whereas opacity applies to all contents of an element, RGBa can apply just to the background and not the text.</p>
<p>So far browsers support the following, which would give a paragraph a red background:</p>
<ul class="code">
<li>p {</li>
<li>background-color: rgb(255, 0, 0);</li>
<li>}</li>
</ul>
<p>With opacity the paragraph&#8217;s background would be transparent but so would the text it contains:</p>
<ul class="code">
<li>p {</li>
<li>background-color: rgb(255, 0, 0);</li>
<li>opacity: 0.5;</li>
<li>}</li>
</ul>
<p>(<strong>Note:</strong> Internet Explorer would require <code>filter: alpha(opacity=50)</code>.)</p>
<p>With rgba we can give the paragraph a 50% transparent background, leaving the text unaltered and allowing anything behind to show through:</p>
<ul class="code">
<li>p {</li>
<li>background-color: rgba(255, 0, 0, 0.5);</li>
<li>}</li>
</ul>
<p>You can also see where <a title="'Playing with CSS...': experiments with css, including RGBa." href="/blog/2009/03/23/playing-with-css3-ie7-fails-of-course/">I&#8217;ve begun playing with rgba</a>.</p>
<ul id="related_posts">
			<li>
					<h4>Possibly related posts</h4>
				 <ol>
								<li>
									<a href="http://citizensheep.com/blog/2009/03/23/playing-with-css3-ie7-fails-of-course/" rel="bookmark">Playing with CSS (IE7 fails, of course)</a><!-- (30.9)-->
							</li>
								<li>
									<a href="http://citizensheep.com/blog/2007/09/10/css-sliding-doors-positioning-the-tabs/" rel="bookmark">CSS ‘sliding doors’: positioning the tabs</a><!-- (17.6)-->
							</li>
								<li>
									<a href="http://citizensheep.com/blog/2010/05/17/scratching-my-head-over-rails/" rel="bookmark">Scratching my head over Rails</a><!-- (5.7)-->
							</li>
					</ol>
			</li>
	</ul>]]></content:encoded>
			<wfw:commentRss>http://citizensheep.com/blog/2007/08/20/transparent-backgrounds-to-text/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

