<?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>Russ Back &#187; CSS</title>
	<atom:link href="http://www.russback.com/articles/css/feed" rel="self" type="application/rss+xml" />
	<link>http://www.russback.com</link>
	<description>Professional Web Development</description>
	<lastBuildDate>Mon, 02 Nov 2009 08:16:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Web standards in a commercial environment</title>
		<link>http://www.russback.com/css/web-standards-in-a-commercial-environment.html</link>
		<comments>http://www.russback.com/css/web-standards-in-a-commercial-environment.html#comments</comments>
		<pubDate>Thu, 23 Apr 2009 19:06:05 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Other stuff]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.russback.com/?p=462</guid>
		<description><![CDATA[I'm a web standards advocate, but there are times when the rules need to be bent when working on large corporate sites, or ecommerce sites where optimisation overrides coding conventions.]]></description>
			<content:encoded><![CDATA[<p>In all I do I have web standards in mind, from developing semantic valid strict or transitional <acronym title="Extensible Hypertext Markup Language">XHTML</acronym>, to developing JavaScript that degrades gracefully. When I&#8217;m developing the presentation layer for a site that uses a <acronym title="Content Management System">CMS</acronym> of any kind, I hate it when I have to work invalid or badly written code and often end up rewriting it myself to improve it. </p>
<p>At the time of writing my current project is the new ecommerce store for <a href="/work/lockonego/" title="Read about the Lockonego project">Lockonego</a>, which is based on <a href="http://www.pinnaclecart.com" title="Visit pinnaclecart.com">Pinnacle Cart</a>. Work began by creating a new skin based on the &#8216;out of the box&#8217; skin but there&#8217;s so much in there that&#8217;s inefficient or just plain wrong, the new skin for Lockonego bears no resemblance to its origins. So it&#8217;s fair to say I&#8217;m a standards junky.</p>
<p>But there are times when you do need to bend the rules slightly and this is the the case at <a href="/work/arcadia-group/" title="Read about my work at Arcadia Group">Arcadia</a>, a £150 million online business with in excess of 5 million page views every day. There are two areas where we&#8217;ve had to compromise and the reasons for each are different:</p>
<h2>Separation of style from content</h2>
<p>One of the founding principles of good development is <a href="http://www.russback.com/search-engine-optimisation/site-logos-and-the-h1-tag.html#working-semantically">separating the markup, style and behaviour out into distinct layers</a> and the main benefit of this is that you can easily update any of the layers without having to update the others. Having an H1 element with style embedded into the markup for example isn&#8217;t best practice. Say you had 50 pages that had an H1 styled in a certain way, you&#8217;d need to add that style to all 50 of those pages and if you changed it, you&#8217;d need to change it in all 50 places. Separating style away to an external <acronym title="Cascading Style Sheet">CSS</acronym> file enables us to define the style in one place, making updates easy.</p>
<p>Even with the use of a CMS template system, you still want to avoid the use of inline styles because if you want to change the layout of a template, you still need to get in there and fiddle with the markup, which should only be used for semantic structure, not styling.</p>
<p>However at Arcadia, we&#8217;ve had to bend this rule slightly. The <a href="/work/arcadia-group/adobe-flex-cms/">custom CMS we&#8217;ve built in Adobe Flex</a> enables our business users to upload images into templates that are built in XHTML and Apache Velocity. This is fine for inline images where we can simply render the image path into an image element in the markup, but not so hot for background images.</p>
<p>At the time of writing each page published from the CMS uses template markup file and one or more template CSS files. However it&#8217;s only the markup file that has data injected into using Velocity. So for a user to insert an image as a background image, we can&#8217;t inject the image information into the external CSS file.</p>
<p>So we bend the rules by externalising every possible style definition to the CSS files and then add the image path (and possibly the dimensions for some template designs) into the markup as an inline style.</p>
<p>So instead of this kind of markup and CSS:</p>
<pre>&lt;!-- markup in the template file --&gt;

&lt;h1&gt;My Headline&lt;/h1&gt;</pre>
<pre>/* styling in the CSS file */

h1 {
 background: url(my-headline.gif) left top no-repeat;
 height: 50px;
 width: 300px;
 text-indent: -9000px;
 }</pre>
<p>We have to do something like this:</p>
<pre>&lt;!-- markup in the template file --&gt;

&lt;h1 style=&quot;background-image: url(my-headline.gif);&quot;&gt;My Headline&lt;/h1&gt;</pre>
<pre>/* styling in the CSS file */

h1 {
 background-position: left top;
 background-repeat: no-repeat;
 height: 50px;
 width: 300px;
 text-indent: -9000px;
 }</pre>
<p>Pesonally I hate it as the rendered markup looks cluttered and unprofessional. But the benefit we gain in being able to offer our business users this kind of flexibility outweigh the concerns of my professional conscience.</p>
<p>I take solace in the fact that the markup is still valid agains the XHTML Transitional doctype, and that if need to update the layout of a set of pages that use a template, I can just edit the template markup file to update each of the pages that use it.</p>
<p>We could do it another way by putting the image inline in place of the live text, but for that&#8217;s a step too far. The only inline images I use are those that make sense when the CSS is disabled. A product photograph for instancem, isn&#8217;t style; it&#8217;s content and therefore lives in the markup. A headline that&#8217;s styled in a fancy font however, is design, not content and therefore belongs in the style layer.</p>
<p>Of course, we could (and need) to develop a way to render our external CSS files based on user input, but for now, this a web standards rule we have to live with.</p>
<h2>Location of JavaScript calls</h2>
<p>The second web standards convention we&#8217;re considering going against is this: that all calls to external JavaScript files should be contained in the head element of the document.</p>
<p>The <a href="http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.1" title="Visit w3.org"><acronym title="WorldWide Web Consortium">W3C</acronym> specify</a> that script elements can be placed anywhere in the head or body, but industry best practice dicates that all of our script should live in the head of the document.</p>
<p>However there is a performance issue to consider, as <a href="http://developer.yahoo.com/performance/rules.html#js_bottom" title="Visit developer.yahoo.com">Yahoo&#8217;s Exceptional Peformance Team point out</a>, scripts block asynchronous <acronym title="HyperText Transfer Protocol">HTTP</acronym> downloads. What this means is that when your browser downloads a page, it attempts to download elements in parallel: one thread might be downloading your CSS file while another is downloading your logo. However when the browser encounters a call to a script file, it blocks all other downloads until it completes as it needs to establish whether the script file is going to need the browser to write content to the view in the form of document.write commands.</p>
<p>The pause may be negligible but in order to optimise the performace of a site, the suggestion from Yahoo is that the scripts of your page should appear at the bottom of the body element so that everything else can download safely.</p>
<p>This is only going to be a viable option if you don&#8217;t use document.write (and let&#8217;s be honest, we should all be using <acronym title="Document Object Model">DOM</acronym> manipulation instead), but one thing we need to investigate further is the impact this has on initiating the scripts themselves.</p>
<p><a href="http://www.jquery.com" title="Visit jquery.com">jQuery</a> and all of the other popular JavaScript libraries provide a way of working with the DOM before the document&#8217;s images downloads, which is great as the behaviour layer can be applied almost instantaneously. But if the browser has already started downloading the imagery for the document, by moving the scripts to the bottom of the body element, have we missed out on that speed of execution? Possibly not, but it needs some further testing so we haven&#8217;t yet moved away from the conventional head location.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.russback.com/css/web-standards-in-a-commercial-environment.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Is it time to stop supporting IE6?</title>
		<link>http://www.russback.com/css/is-it-time-to-stop-supporting-ie6.html</link>
		<comments>http://www.russback.com/css/is-it-time-to-stop-supporting-ie6.html#comments</comments>
		<pubDate>Sun, 19 Apr 2009 09:18:20 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Other stuff]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.russback.com/?p=453</guid>
		<description><![CDATA[Pressure to kill of <acronym title="Internet Explorer version 6">IE6</acronym> is building amongst the web design and development community and some organisations have already foresaken it. But it's probably not going to be that simple.]]></description>
			<content:encoded><![CDATA[<p>Microsoft recently announced that <a href="http://blogs.msdn.com/ie/archive/2009/04/10/prepare-for-automatic-update-distribution-of-ie8.aspx" title="Visit blogs.msdn.com">IE8 will be listed as a high priority item in the Windows Update service</a>, which can only be a good thing. Firefox 3 for example has all but killed off legacy versions 1 and 2, perhaps partly because its users tend to be more tech-aware than your average IE user, but the more likely reason would seem to be the upgrade strategy Mozilla take &#8211; alerting you that an upgrade is available and enticing you to upgrade.</p>
<p>Windows Update isn&#8217;t as pervasive as Mozilla&#8217;s method though. I&#8217;ve seen regular users of the web completely ignore the Windows Update icon in their system tray so the IE8 message isn&#8217;t going to be on their radar. Then there&#8217;s the huge number of corporates out there that have Windows Update turned off or who have not yet rolled out IE7 onto their standard build, let alone IE8.</p>
<p>Finally, there&#8217;s the lowest common denominator: the computers whose specifications are so low that IE8 simply aint gonna be an option. It&#8217;s all too easy to think that those on these kind of computers aren&#8217;t going to be the type of visitors you&#8217;re seeking &#8211; perhaps they&#8217;re not your typical online gamer or don&#8217;t buy all of their luxury items online &#8211; but they&#8217;ll also include public environments such as libraries and community centres that don&#8217;t have the budget to upgrade their kit.</p>
<p>I expect to see IE8 gain a fairly rapid hold on the IE market but I&#8217;m still expecting to have to continue coding around the inadequacies of IE6 for some time. As much as the prospect of CSS3 and HTML5 amongst <a href="http://www.sitepoint.com/blogs/2009/04/14/10-cool-things-well-be-able-to-do-once-ie6-is-dead/" title="Visit sitepoint.com">other things</a> is exciting, from a commercial point of view, in the world of ecommerce I can&#8217;t afford to ignore a part of my user base that spend money with us using IE6. But there is a tipping point.</p>
<p>A fair amount of time and effort (and therefore money) goes into ensuring sites offer the best user experience in both modern and legacy browsers; how much will depend on the site and its business. While that cost is outweighed by the income derived from IE6 visitors, it&#8217;s fair to say that we should still look to support IE6. The point at which each business decides it&#8217;s no longer commercially worthwhile is going to differ on a case-by-case basis, but some have already made the leap.</p>
<p><a href="http://www.37signals.com/" title="Visit 37signals.com">37signals</a> have given up the ghost. That&#8217;s not to say that their site is no longer usable in IE6, but it&#8217;s not got the same level of polish, as indicated by the difference in design caused by IE6&#8217;s lack of support for PNG transparency.</p>
<h3>37signals.com in Firefox 3</h3>
<p><img src="http://www.russback.com/wp-content/uploads/screenshot-37signals-firefox.jpg" alt="Screenshot of 37signals.com in Firefox 3" width="553" height="209" class="alignnone size-full wp-image-455" /></p>
<h3>37signals.com in IE6</h3>
<p><img src="http://www.russback.com/wp-content/uploads/screenshot-37signals-ie6.jpg" alt="Screenshot of 37signals.com in IE6" width="553" height="209" class="alignnone size-full wp-image-456" /></p>
<p>There are others (like Yahoo&#8217;s <a href="http://www.wait-till-i.com/2009/04/02/easing-the-transition-from-ie6-to-using-newer-browsers/" title="Visit wait-till-i.com">Christian Heilman</a> and the popular <a href="http://www.netmag.co.uk/zine/home/calling-time-on-IE6" title="Vist netmag.co.uk">web design magazine .Net</a>), are keen to see IE die, and there&#8217;s even talk of a return to <a href="http://code.google.com/p/ie6-upgrade-warning/" title="Visit code.google.com">scripts that will detect IE6</a> and alert the user that they should upgrade. For me this is a step too far back to old days when sites had to have a particular browser. Ironically enough it was typically Firefox and Safari users who were blocked from accessing sites because they weren&#8217;t using&#8230; IE6!</p>
<p>And then <a href="http://www.saveie6.com/index.php" title="Visit saveie6.com">there are those that think IE6 should be saved</a>. OK, so maybe this one&#8217;s toung-in-cheek, but I think we&#8217;ll be stuck with IE6 for a little while longer yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.russback.com/css/is-it-time-to-stop-supporting-ie6.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple cross-browser CSS transparency</title>
		<link>http://www.russback.com/css/simple-cross-browser-transparency.html</link>
		<comments>http://www.russback.com/css/simple-cross-browser-transparency.html#comments</comments>
		<pubDate>Mon, 23 Mar 2009 21:28:39 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[transparency]]></category>

		<guid isPermaLink="false">http://www.russback.com/?p=218</guid>
		<description><![CDATA[CSS transparency can be a pain, particularly in legacy browsers like IE6. This article covers a simple technique to achieve cross-browser transparency without JavaScript or an HTC fix.]]></description>
			<content:encoded><![CDATA[<p>Whilst there are different ways of achieving transparency, such as the <a title="Visit twinhelix.com" href="http://www.twinhelix.com/css/iepngfix/">HTC fix for PNG images</a>, when you simply need an element on your page to be semi-transparent so that you can see the background behind, the approach below should serve you well.</p>
<p>Each of these examples uses the image below, which is shown here as a refererence:</p>
<p><img class="alignnone size-full wp-image-265" title="Photo of leaves used as an example" src="http://www.russback.com/wp-content/uploads/example-bgrd.jpg" alt="Photo of leaves used as an example" width="553" height="125" /></p>
<h2>Transparent background and content</h2>
<p>All modern browsers recognise the opacity filter so this is our starting point. IE uses a different style declaration to the rest of our <a href="#browser-compatibility">target browsers</a> so our basic CSS class for a transparent element looks like this:</p>
<pre>.transparent {
	background: #FFF;
	opacity: .50;
	filter: alpha(opacity=50);
	width: 100% !important;
	}</pre>
<p>The background and opacity values could be anything you need but I&#8217;m setting these to white and 50% by default as this give us an effect that works well in may situations. The two opacity declarations are for different browsers: filter for IE, opacity for everybody else. The need for a width declaration is an odd one; without it, IE6 doesn&#8217;t invoke the filter so make sure you have a width set.</p>
<p>Here&#8217;s an example showing the background image and a paragraph of text overlaying it with the default 50% tranparency:</p>
<pre>&lt;p class="transparent"&gt;This text is inside a paragraph element with the classname .transparent and should have a transparency value of 50%. The opacity should change when you roll over it.&lt;/p&gt;</pre>
<div class="example example_1">
<p class="transparent">This text is inside a paragraph element with the classname .transparent and should have a transparency value of 50%</p>
</div>
<p>You could say that there&#8217;s an issue with this though in that although we&#8217;ve achieved a transparent background, we&#8217;ve also made the text inside the block transparent too. You could equally say this is exactly what you want; for example you might want the transparency to change on rollover, which could simply be achieved by adding the the following psuedo class that adjusts the opacity on rollover (I&#8217;ve added a cursor for good measure):</p>
<pre>.transparent:hover {
	opacity: .80;
	filter: alpha(opacity=80);
	cursor: pointer;
	}</pre>
<p>(If	you&#8217;re looking to do this for IE6 you&#8217;ll need to make sure the :hover pseudo class is on a link element rather than a paragraph or any other element.)</p>
<div class="example example_2">
<p class="transparent">This text is inside a paragraph element with the classname .transparent and should have a transparency value of 50%. The opacity should change when you roll over it.</p>
</div>
<p>Setting the opacity of the element makes the whole element &#8211; background and content &#8211; transparent, so we need another solution if we want a transparent background and opaque text.</p>
<h2>Transparent background, opaque content</h2>
<p>As shown above, setting the opacity of the element makes the whole element transparent so any child elements will be transparent too. So if we want opaque elements showing on top of transparent elements, we need to keep the two elements in their own node in the <abbr title="Document Object Model">DOM</abbr>.</p>
<p>In the example above, we had a single transparent paragraph element with text. As the text is a node of the paragraph, the transparency is inherited but the same would apply to any nodes in more complex markup. Take a look at the wireframe here:</p>
<p><img class="alignnone size-full wp-image-282" title="Wireframe of example 1" src="http://www.russback.com/wp-content/uploads/wireframe-1.gif" alt="Wireframe of example 1" width="553" height="93" /></p>
<p>The content element is a child of the transparent element and is therefore itself transparent. What we need is something like this:</p>
<p><img class="alignnone size-full wp-image-283" title="Wireframe of what we want" src="http://www.russback.com/wp-content/uploads/wireframe-2.gif" alt="Wireframe of what we want" width="553" height="109" /></p>
<p>As the content element is not a child of the transparent element, it will be fully opaque. All that&#8217;s left to do is style this so that the content sits on top of the background element, which we can achieve reliably by adding a wrapper around both elements as follows:</p>
<p><img class="alignnone size-full wp-image-284" title="Wireframe of what we'll need to achieve this effect" src="http://www.russback.com/wp-content/uploads/wireframe-3.gif" alt="Wireframe of what we'll need to achieve this effect" width="553" height="153" /></p>
<p>The semantic XHTML for this should be something like this:</p>
<pre>&lt;div class="transparent_wrapper"&gt;
&lt;div class="transparent transparent_bgrd"&gt;&lt;/div&gt;
&lt;p class="opaque_content"&gt;The text is inside a paragraph with the classname .opaque_content and should be opaque on top of the transparent background elemnent.&lt;/p&gt;
&lt;/div&gt;</pre>
<p>The	empty div inside the wrapper will contain the transparent background and the content element (in this case a paragraph but this could be any element) needs to be positioned on top of the background, which we can achieve with CSS as follows, which I&#8217;ll go through step by step&#8230;</p>
<h3>The transparent background element</h3>
<p>The background (colour or image, depending on your needs) needs to sit under the content so we start off by setting its position absolutely. By default browsers assume an absolute element should sit 0 from the top and left so we don&#8217;t need to declare these properties, however we do need to ensure that the background appears underneath the content, so we set the z-index to be 1.</p>
<p>Assuming we want to reuse this technique for a multitude of designs and layouts, we need to make sure the background scales as the content size increases. To do this we set a 100% height for modern browsers, and a pixel value for IE6, which struggles with the 100% declaration (I&#8217;ve used 9000px here which will more than comfortably cover anything I need). We can do this in one selector by declaring 100% as the height first with the !important declaration. After this we add the pixel value for IE6. Modern browsers will obey the !important declaration but IE6 incorrectly ignores it, so we&#8217;ve achieved everything we need without any complicated hacks.</p>
<pre>.transparent_bgrd {
	position: absolute;
	z-index: 1;
	width: 100%;
	height: 100% !important;
	height: 9000px;
	}</pre>
<h3>The opaque content element</h3>
<p>The content element is simple. It simply needs to overlay the background element within the wrapper, which we can achieve simply by setting a higher z-index value and a relative top position of 0px. We could use absolute positioning but the benefit of using relative positioning is that the wrapper (and therefore the 100% height transparent background element) will scale according to the height of the content.</p>
<pre>.opaque_content {
	position: relative;
	top: 0;
	z-index: 2;
	}</pre>
<h3>Wrapping it all up</h3>
<p>The wrapper acts as a bounding box for the two child elements. The first thing to do with the wrapper is to set it to position:relative to ensure that the child elements will take coordinates according to this wrapper element. For IE6 to render the background reliably when the content scales, we also set the height of the wrapper to 100% and set the overflow value to hidden to ensure whatever remains of the 9000px setting declared in the background element is hidden from view.</p>
<p>We also want to ensure that the wrapper can be used for any content</p>
<pre>.opaque_content {
	position: relative;
	top: 0;
	z-index: 2;
	}</pre>
<p>Here&#8217;s the updated example using this approach:</p>
<div class="transparent_wrapper example">
<div class="transparent transparent_bgrd">&nbsp;</div>
<p class="opaque_content">The text is inside a paragraph with the classname .opaque_content and should be opaque on top of the transparent background elemnent.</p>
</div>
<h2>Download and customise the source code</h2>
<p>The background image used in the examples above is only 125px high, so obviously it&#8217;s not good enough to use as a background image on large elements; it&#8217;s simply used here as an example. You could just as easily use a background colour instead of an image. I find the best approach is to keep the core styles in my master stylesheet and then add specific styling to each element that uses it. You can grab the complete set of examples and core code in the <a title="Download the ZIP file of this source code" href="/wp-content/uploads/simple-cross-browser-transparency.zip">source code for this example</a>.</p>
<h2><a name="browser-compatibility"></a>Browser compatibility</h2>
<table border="0" cellspacing="0" cellpadding="0" width="95%">
<tbody>
<tr>
<th scope="col">Browsers *</th>
<th scope="col">Fully tested</th>
</tr>
<tr>
<td>Firefox 3</td>
<td class="yes">Yes</td>
</tr>
<tr>
<td>Firefox 2</td>
<td class="yes">Yes</td>
</tr>
<tr>
<td>Internet Explorer 8 <del>Beta</del></td>
<td class="yes">Yes</td>
</tr>
<tr>
<td>Internet Explorer 7</td>
<td class="yes">Yes</td>
</tr>
<tr>
<td>Internet Explorer 6</td>
<td class="yes">Yes</td>
</tr>
<tr>
<td>Safari 3</td>
<td class="yes">Yes</td>
</tr>
<tr>
<td>Google Chrome 1</td>
<td class="yes">Yes</td>
</tr>
<tr>
<td>Opera 10</td>
<td class="yes">Yes</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.russback.com/css/simple-cross-browser-transparency.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
