<?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>Blue Anvil Journal &#187; hacks</title>
	<atom:link href="http://blue-anvil.com/tag/hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://blue-anvil.com</link>
	<description>The online blogfolio of Mike Jolley</description>
	<lastBuildDate>Sun, 05 Sep 2010 14:39:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Window Resize/Mobile Browser Background Bugs</title>
		<link>http://blue-anvil.com/archives/window-resizemobile-browser-background-bugs/</link>
		<comments>http://blue-anvil.com/archives/window-resizemobile-browser-background-bugs/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 11:25:52 +0000</pubDate>
		<dc:creator>Mike Jolley</dc:creator>
				<category><![CDATA[Browsers & Hacks]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[compatibility]]></category>
		<category><![CDATA[cross browser]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[fixes]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://blue-anvil.com/?p=122</guid>
		<description><![CDATA[Last week I noticed something very odd on Blue Anvil when resizing the browser window; after some casual browsing I discovered it was not just my site with the problem and that it was quite widespread on many &#8216;web 2.0&#8242; style sites. The problem occurs when resizing the browser window; cutting off background images and [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blue-anvil.com/img/bugs.gif" class="floatleft" style="float:left;margin:0 4px 2px 0;" alt="Background Bugs" /> Last week I noticed something very odd on Blue Anvil when resizing the browser window; after some casual browsing I discovered it was not just my site with the problem and that it was quite widespread on many &#8216;web 2.0&#8242; style sites.</p>
<p>The problem occurs when resizing the browser window; cutting off background images and potentially making text illegible. Worse still, the bug also seems to affect mobile browsers with a zoom function, such as opera mobile.</p>
<p>After some dabbling I found a solution, which I shall explain in this post.</p>
<p><span id="more-122"></span></p>
<p>The sites that are most affected are those that use &#8216;content strips&#8217; as I like to call them; that is a full width background with content centered down the middle. I tend to code a &#8216;strip&#8217; like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;header&quot;&gt;
     &lt;div class=&quot;inner&quot;&gt;
          ...Content goes here...
     &lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>In this example #header is a block level element making it full width with a background image (usually tiled). .inner is my content div; it has a width set and auto-margins to make it centered on the page. The diagram below shows the structure of the layout on blue anvil:</p>
<p><img src="http://blue-anvil.com/wp-content/uploads/2008/07/diagram.jpg" alt="Layout Diagram" title="diagram" width="280" height="200" class="aligncenter size-full wp-image-125" /></p>
<p>If you make the window smaller and then use the horizontal scrollbar in the browser window you will notice the background gets &#8216;cut-off&#8217;. This seems to affect all modern browsers. From what I can gather, it seems the divs with the background image resize with the browser window, meaning any fixed width content will spill out and be shown on the page background; <a href="http://blue-anvil.com/tuts/bgbugdemo.html">this demo page has the bug for you to see</a>.</p>
<p><p style="text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-6928386133078955";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "444444";
google_color_text = "444444";
google_color_url = "444444";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p></p>
<p>The problem itself is not major for most people, since (I assume) resizing the window and scrolling is quite rare. However I have noticed it happening before on the Nintendo Wii browser, and some mobile browsers (opera mobile for instance) where the problem can be more severe; its more of a problem on these devices because It can prevent the user from being able to read content. For example, when opera mobile cut the background off of the footer on Blue Anvil the white text was not legible, as this screenshot shows (taken from my HTC Diamond using Opera Mobile before I fixed the layout):</p>
<p><img src="http://blue-anvil.com/wp-content/uploads/2008/07/bug_mobile.jpg" alt="Bug on Opera Mobile" title="bug_mobile" width="150" height="200" class="aligncenter size-full wp-image-123" /></p>
<p>I experimented with all sorts of attempted fixes; wrappers, 100% widths, clearing&#8230;nothing seemed to work at first. In the end I found a workable solution which was actually quite simple: <strong><code>min-width</code></strong>. Using min-width on the div with the background prevented the browser from shrinking it too much hence eliminating the problem.</p>
<p><img src="http://blue-anvil.com/wp-content/uploads/2008/07/fixed.jpg" alt="Fixed Bug" title="fixed" width="150" height="200" class="aligncenter size-full wp-image-124" /></p>
<p>This fix is quite simple and does not seem to affect anything else on the page or cause any issues of its own, so it is something which can be added easily to any layout suffering from this problem.</p>
<p>Enjoy.</p>
<img src="http://blue-anvil.com/7dc46085/266bbf6b/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></content:encoded>
			<wfw:commentRss>http://blue-anvil.com/archives/window-resizemobile-browser-background-bugs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>How to&#8230;use conditional comments</title>
		<link>http://blue-anvil.com/archives/how-touse-conditional-comments/</link>
		<comments>http://blue-anvil.com/archives/how-touse-conditional-comments/#comments</comments>
		<pubDate>Sat, 05 Aug 2006 13:48:59 +0000</pubDate>
		<dc:creator>Mike Jolley</dc:creator>
				<category><![CDATA[Browsers & Hacks]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[conditional comments]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://82.110.105.91/blue-anvil.co.uk/?p=15</guid>
		<description><![CDATA[Conditional comments have been part of internet explorer since version 5, but a lot of programmers ignore them. This article teaches the basics of using conditional comments, and shows some examples of their uses. A conditional comment is a method of talking directly to a version of internet explorer above version 5, allowing you to [...]]]></description>
			<content:encoded><![CDATA[<p>Conditional comments have been part of internet explorer since version 5, but a lot of programmers ignore them.</p>
<p>This article teaches the basics of using conditional comments, and shows some examples of their uses.</p>
<p><span id="more-15"></span><br />
<p style="text-align:center"><script type="text/javascript"><!--
google_ad_client = "pub-6928386133078955";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "444444";
google_color_text = "444444";
google_color_url = "444444";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p></p>
<p>A conditional comment is a method of talking directly to a version of internet explorer above version 5, allowing you to pass<br />
IE specific rules without affecting other browsers such as firefox.</p>
<p>By utilizing conditional comments you can effectively reduce the usage of css hacks to make your web pages compatible with<br />
Internet explorer.</p>
<h2>Common uses</h2>
<p>With conditional comments you can:</p>
<ul>
<li>Target IE specifically</li>
<li>Make IE 5+ ignore a block of code</li>
</ul>
<p>A great usage, for example, would be using conditional comments with CSS style sheets so you can have certain IE specific css rules that you want other browsers to ignore.</p>
<h2>The code</h2>
<p>You may be aware that, in html, the syntax of a normal comment is:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--comment goes here--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>Comments can be placed anywhere in the document.</p>
<p>Now, a conditional comment looks like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!<span style="color: #00AA00;">&#91;</span>if <span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>Conditional comments can also be placed anywhere in your HTML document.</p>
<h2>Types of conditional comment</h2>
<h3>downlevel-hidden</h3>
<p>A <em>downlevel-hidden</em> comment is a comment that is visible <strong>only</strong> to the IE version you are targeting.</p>
<p><strong>Example:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if IE<span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
     &lt;em<span style="color: #00AA00;">&gt;</span>your code&lt;/em<span style="color: #00AA00;">&gt;</span>
&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>The above code will only be seen by IE versions 5 and up.</p>
<p>Other, older, versions of IE, and also other browsers, will not see the code enclosed by the tags, and will therefore ignore anything you put inside, hence the name, <em>downlevel-<strong>hidden</strong></em>.</p>
<p>The other browsers just see the &lt;&#8211; and &#8211;&#038;rt parts, so it looks like a regular comment to them.</p>
<p>Just to show you, for reference, if you used the code,</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if !IE<span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
     &lt;em<span style="color: #00AA00;">&gt;</span>your code&lt;/em<span style="color: #00AA00;">&gt;</span>
&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>NO browser would see the code. This is because the rule is !IE, which means <em>NOT IE</em>. Therefore IE 5+ wont see the code, and since it is downlevel hidden, no other browsers will either.</p>
<p><strong>Visibility conclusion:</strong></p>
<p>Firefox/non-ie browsers &#8211; code hidden</p>
<p>Targeted IE &#8211; code visible</p>
<h3>downlevel-revealed</h3>
<p>A <em>downlevel-revealed</em> comment is a comment that is visible to the IE version you are targetting, and also non-IE browsers and old versions of IE. It is useful when you wish to make code invisible to a version of internet explorer, but you want non-IE browsers to still see it.</p>
<p><strong>Example:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!<span style="color: #00AA00;">&#91;</span>if !IE<span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
     &lt;em<span style="color: #00AA00;">&gt;</span>your code&lt;/em<span style="color: #00AA00;">&gt;</span>
&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>The above example would be visible to all browsers except IE versions 5+.</p>
<p><strong>Validity</strong></p>
<p>You may notice that the downlevel-revealed code provided by Microsoft does not validate correctly, the correct code is outlined on <a href="http://www.456bereastreet.com/archive/200511/valid_downlevelrevealed_conditional_comments/">this page</a>, or is shown below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if !IE<span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>--<span style="color: #00AA00;">&gt;</span>
     &lt;em<span style="color: #00AA00;">&gt;</span>your code&lt;/em<span style="color: #00AA00;">&gt;</span>
&lt;!--&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>The difference between this downlevel-revealed code and the downlevel-hidden code is that the comment is closed after each line, so non-IE browsers will not ignore it.</p>
<p><strong>Visibility conclusion:</strong></p>
<p>Firefox/non-ie browsers &#8211; code visible</p>
<p>Targeted IE &#8211; code visible</p>
<h2>Targeting specific IE versions and extra commands</h2>
<p>The <em>[if ]</em> portion of the conditional comment code has extra functionality so you can target certain versions of IE, or exclude versions. These are outlined below.</p>
<h3>Targeting an IE version</h3>
<p>To target a specific version of IE you just add the version number in the <em>if</em> statement, for example, to target IE 6 only you could use:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if IE <span style="color: #cc66cc;">6</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
     &lt;em<span style="color: #00AA00;">&gt;</span>your code&lt;/em<span style="color: #00AA00;">&gt;</span>
&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>You must leave a space between &#8216;IE&#8217; and the version number.</p>
<h3>Targeting multiple IE versions</h3>
<p>If, for example, you wanted to target versions of IE older than IE 6, rather than writing individual statements for each version you could use the <em>&#8216;less than&#8217;</em> comparison :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if lt IE <span style="color: #cc66cc;">6</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
     &lt;em<span style="color: #00AA00;">&gt;</span>your code for versions less than IE <span style="color: #cc66cc;">6</span><span style="color: #00AA00;">,</span> but not including IE <span style="color: #cc66cc;">6</span>&lt;/em<span style="color: #00AA00;">&gt;</span>
&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>If you wanted to target versions older than, and equal to IE6 you would use:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if lte IE <span style="color: #cc66cc;">6</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
     &lt;em<span style="color: #00AA00;">&gt;</span>your code&lt;/em<span style="color: #00AA00;">&gt;</span>
&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>The commands for comparing versions are as follows:</p>
<p><strong>lt</strong> &#8211; less than</p>
<p><strong>lte</strong> &#8211; less than or equal too</p>
<p><strong>gt</strong> &#8211; greater than</p>
<p><strong>gte</strong> &#8211; greater than or equal too</p>
<h3>Excluding an IE version/versions</h3>
<p>To exclude a version you can make use of the ! (NOT) operator, for example, to target all IE versions except IE 6 you could use:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if !IE <span style="color: #cc66cc;">6</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
     &lt;em<span style="color: #00AA00;">&gt;</span>your code&lt;/em<span style="color: #00AA00;">&gt;</span>
&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>This would mean <em>if not ie 6</em>.</p>
<p>You could also mix the not operator with multiple IE versions, for example to target all versions of IE except IE 6 and above you could use the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if gte !IE <span style="color: #cc66cc;">6</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
     &lt;em<span style="color: #00AA00;">&gt;</span>your code&lt;/em<span style="color: #00AA00;">&gt;</span>
&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>This would mean <em>if not greater than or equal to ie 6</em>.</p>
<h3>Version Vectors</h3>
<p>Version vectors allow you to target minor versions of IE, for example you could target IE 5.5 instead of IE 5 as a whole. This is particularly useful, as some bugs are fixed in higher versions. The format of a version vector is x.xxxx, but you do not have to make the decimal 4 digits long, e.g 5.0 is valid, as is 5.0000, however the 5.0000 targets the 0000 build of the browser specifically.</p>
<h2>Usage examples</h2>
<p>Some of the best example of usage would be using conditional comments in conjunction with CSS. Say for instance you wanted to fix a box model error in IE 5, rather than use hacks you could just make a separate style sheet for IE 5 with modified width values of an element which wasn’t rendering correctly. You would then add the following to the header of the html page:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if IE <span style="color: #cc66cc;">5</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
  &lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
    <span style="color: #a1a100;">@import url(ie5.css);</span>
  &lt;/style<span style="color: #00AA00;">&gt;</span>
&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>And hey presto, IE 5 will use the fixed styling, no box model hacks needed. Of course with this method you would have to ensure the conditional comment was after the style sheet include, if not the style would be overwritten by the default style sheet. Of course another method that would not be affected by the order would be to just add the styling directly to the conditional comment :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if IE <span style="color: #cc66cc;">5</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
  &lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
    <span style="color: #cc00cc;">#element</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
  &lt;/style<span style="color: #00AA00;">&gt;</span>
&lt;!<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>Since styles in the document have a higher priority than those in the style sheets, it would take priority.</p>
<p>So there you have it, a simple guide to using conditional comments in your web pages to avoid hacks, I hope this was useful and don’t forget to post a comment. Thanks for reading!</p>
<h2>Further reading</h2>
<p><a href="http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp">Microsofts conditional comments page</a></p>
<img src="http://blue-anvil.com/7dc46085/266bbf6b/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></content:encoded>
			<wfw:commentRss>http://blue-anvil.com/archives/how-touse-conditional-comments/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>My day of buggy hell with IE &#8211; a css story</title>
		<link>http://blue-anvil.com/archives/my-day-of-buggy-hell-with-ie-a-css-story/</link>
		<comments>http://blue-anvil.com/archives/my-day-of-buggy-hell-with-ie-a-css-story/#comments</comments>
		<pubDate>Sun, 30 Jul 2006 13:48:15 +0000</pubDate>
		<dc:creator>Mike Jolley</dc:creator>
				<category><![CDATA[Browsers & Hacks]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[conditional comments]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[fixes]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://82.110.105.91/blue-anvil.co.uk/?p=14</guid>
		<description><![CDATA[As you may well be aware, this has been a pretty hectic week for me, trying to finish all my projects before I leave to go on a well earned holiday. The main thing on my agenda was the blue anvil redesign I&#8217;ve been working on. It all went pretty smoothly, excluding the few set-backs [...]]]></description>
			<content:encoded><![CDATA[<p>As you may well be aware, this has been a pretty hectic week for me, trying to finish all my projects before I leave to go on a well earned holiday.</p>
<p>The main thing on my agenda was the blue anvil redesign I&rsquo;ve been working on. It all went pretty smoothly, excluding the few set-backs I encountered (see my last blog entry), but all in all it went well and the website was looking fairly nice&#8230;in firefox.</p>
<p>Yes, I left the cross browser stuff until last, it would only take an hour or two, right? How wrong was I. This was my day from hell and I have the coffee breath and bad temperament to prove it. With any luck the problems and solutions I used may be<br />
helpful, and save others from a hellish day that I experienced.</p>
<p><span id="more-14"></span></p>
<h2>Bug #1 &#8211; Negative margins</h2>
<p>Negative margins have a variety of uses, I love them to bits. Great for overlapping content or escaping a div. This bug wasn&rsquo;t bad at all, Id experienced it before, and it does make sense why it goes wrong really.</p>
<p>In my case I have a div with padding which my content was being put into. Above the content I wanted to have a strip for the date that was wider then the content itself.</p>
<p>Rather than fiddle with padding, or adding more divs, I went down the negative margin route.</p>
<h3>The code</h3>
<p>The strip was in a box with a padding of 32px.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.date_strip</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">32px</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-32px</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">-32px</span><span style="color: #00AA00;">;</span> 
<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>The problem</h3>
<p>The code works as it should in firefox, but IE cuts off the edges of the strip.</p>
<h3>The solution</h3>
<p>Simply add the rule:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span></pre></td></tr></table></div>

<p>Later on in the day (just before I had the urge to put the laptop in the oven and watch it die) I found a second error, this one with Opera 9. Opera 9 would render the left negative margin fine, but cut off the right hand side. To fix this I just added padding to right, as I already did to the left.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">32px</span></pre></td></tr></table></div>

<h3>Bug conclusion</h3>
<p><strong>Difficulty rating:</strong> 1/10 <strong>Annoyance factor:</strong> 1/10</p>
<h2>Bug #2 &#8211; Form heights</h2>
<p>If you look in the sidebar you will see the search form, I had some problems regarding the height of the input box and the height of the submit button.</p>
<h3>The code</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#searchbox</span> input <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#73B531</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">125px</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#searchbox</span> input<span style="color: #6666ff;">.button</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#8C4</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#692</span><span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">75px</span> !important<span style="color: #00AA00;">;</span>  
<span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">4px</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>The problem</h3>
<p>Firefox renders the button with more height than the input box. This was happening when my input button had a border.</p>
<p>I thought that simply adding one pixel of padding to the input box would solve the problem, and it did, but this made IE render the boxes at different heights. To solve this I needed to add<br />
<em>2 padding</em> to the input box, which broke firefox.</p>
<h3>The solution</h3>
<p>Conditional comments were the key to solving this bug. By setting the padding to 1px in the css stylesheet (fixing firefox) i could add a conditional comment to make IE render the same box with 2px padding, solving the problem.</p>
<p>In the header of the document:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!--[if IE]&gt;
      &lt;style&gt;
      #searchbox input{padding:2px;}
      #searchbox input.button{padding:0;}
      &lt;/style&gt;
&lt;![endif]--&gt;</pre></td></tr></table></div>

<p>(check back in a few weeks, I will be covering conditional comments in more detail in a future post).</p>
<p>Despite this there is still a problem, as the boxes are not equal height in opera, as of yet I have not been able to solve this as I cannot find a hack for opera that works well. If you know one, please leave a comment.</p>
<h3>Bug conclusion</h3>
<p><strong>Difficulty rating:</strong> 3/10 <strong>Annoyance factor:</strong> 7/10</p>
<h2>Bug #3 &#8211; accessible forms</h2>
<p>I was quite disappointed when I found this bug, as I thought my forms were perfect. Well it seems IE has a nasty quirk concerning field set backgrounds.</p>
<p>In firefox and other standard compliant browsers, the field set background goes up to the border, as it should.</p>
<p>In internet explorer the field set background breaks out of the border to fill the legend (the label for the field set) too, making it very difficult to make the forms look the same between browsers.</p>
<h3>The code</h3>
<p>CSS:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#commonform</span> fieldset <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#8FA7C2</span><span style="color: #00AA00;">;</span>  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#commonform</span> legend <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#dbdbdb</span><span style="color: #00AA00;">;</span>  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#7191B0</span><span style="color: #00AA00;">;</span>   <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">1.2em</span><span style="color: #00AA00;">;</span>  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#efefef</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>images/bits2.png<span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>HTML</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;fieldset&gt;
&lt;legend&gt;Your Contact Details&lt;/legend&gt;...etc</pre></td></tr></table></div>

<h3>The solution</h3>
<p>To fix the problem in IE, I found that the only way was to position the legend absolutely to the relatively positioned field set, essentially breaking it from the flow so the background wouldn&rsquo;t fill the legends area. The code is quite fiddly to get right, and only works in IE, therefore conditional comments come in handy once again.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!--[if IE]&gt;
      &lt;style&gt;
      #commonform fieldset {margin:0;  margin-bottom:16px;  &lt;strong&gt;position:relative ;&lt;/strong&gt;  background-color:#fff;  border:1px solid #8FA7C2;  padding:16px;}
      #commonform legend {&lt;strong&gt;position:absolute;&lt;/strong&gt;  margin-top:-26px;  font-weight:bold;  border-bottom:1px solid #dbdbdb;  color:#7191B0;  font-size:1.2em;  background:#efefef url(images/bits2.png) repeat-x}
      &lt;/style&gt;
&lt;![endif]--&gt;</pre></td></tr></table></div>

<h3>Bug conclusion</h3>
<p><strong>Difficulty rating:</strong> 8/10 <strong>Annoyance factor:</strong> 8/10</p>
<h2>Bug #4 &#8211; Safari wrap bug</h2>
<p>This was a quick bug I found with my navbar. My navbar is essentially just an inline list with padding above and below. Its width is set with display:block;.</p>
<h3>The problem</h3>
<p>Safari would break the list, causing the last item to wrap, breaking the layout.</p>
<h3>The solution</h3>
<p>Simply adding <code>white-space:nowrap;</code> to the navigation container solved the issue.</p>
<h3>Bug conclusion</h3>
<p><strong>Difficulty rating:</strong> 1/10 <strong>Annoyance factor:</strong> 1/10</p>
<h2>Bug #5 &#8211; Internet explorer making content disappear a.k.a peek-a-boo bug</h2>
<p>I&rsquo;m not sure if this was the peek-a-boo bug for sure, but strangely it also happened in IE7, which is a bit of a downer considering they were supposed to fix it!</p>
<p>Anyway what happened is that sometimes when scrolling content would randomly vanish, also background images would disappear revealing the background colour of the page.</p>
<p>This bug probably took the longest to fix, simply because I hadn&rsquo;t encountered it before.</p>
<h3>The fix</h3>
<p>I found a fix by searching, and it seemed rather odd to me, but somehow it worked. It was called the holly hack, and applied a height of 1% to the box with the problem in IE, causing the background to fill the box correctly. Hoorah.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* \*/</span>
<span style="color: #00AA00;">*</span> html  <span style="color: #6666ff;">.block</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">1</span>%</span><span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">;</span>
<span style="color: #808080; font-style: italic;">/* */</span></pre></td></tr></table></div>

<p>Note that the rule after this hack can be ignored, so it is best to insert a dummy rule afterwards e.g. *{margin:0;}.</p>
<h3>Bug conclusion</h3>
<p><strong>Difficulty rating:</strong> 6/10 <strong>Annoyance factor:</strong> 10/10</p>
<h2>Bug #6 &#8211; Image/background image positioning bug</h2>
<p>My banner image is actually two images, one background (the sunburst), and the logo. The logo is just inserted inside a div<br />
with padding to make it taller. It also has a background image using the css:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#557799</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/burst.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">;</span></pre></td></tr></table></div>

<p>In firefox the image lines up perfectly, however IE looks like the background image is not aligned to the bottom left perfectly, and is shifted slightly.</p>
<h3>The fix</h3>
<p>By adding a conditional comment to add negative margins to my logo, I can line the image up manually so it works in both browsers.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!--[if IE]&gt;
    &lt;style&gt;
      #header img{position:relative;margin-bottom:-4px;}
    &lt;/style&gt;
&lt;![endif]--&gt;</pre></td></tr></table></div>

<h3>Bug conclusion</h3>
<p><strong>Difficulty rating:</strong> 5/10 <strong>Annoyance factor:</strong> 7/10</p>
<h2>Bug #7 &#8211; Doubled margins bug</h2>
<p>If you are a coder there&rsquo;s a 99% chance you have encountered this bug before.</p>
<p>For some reason IE doubles the margins of floated elements, this is do to a bug in the engine.</p>
<h3>The fix</h3>
<p>This ones easy, just add <strong>display:inline</strong> to the floated element!</p>
<h3>Bug conclusion</h3>
<p><strong>Difficulty rating:</strong> 1/10 <strong>Annoyance factor:</strong> 2/10</p>
<h2>Bug #8 &#8211; Box model</h2>
<p>Like the above bug, this is probably the most common IE bugs encountered due to the fact IE 5 renders the box model differently to standards based browsers.</p>
<p>To put it simply, standards browsers render the width of a div with the width + the padding, whereas IE 5 renders the width of a div with the set width &#8211; the padding.</p>
<p>So for standards browsers, if you wanted a box 200px wide with a 10px padding left and right, you would set:</p>
<p>width: 180px; padding:10px;</p>
<p>But IE would show the box just as 180px wide, not 200px (width + padding).</p>
<h3>The solution</h3>
<p>There are many solutions to this common problem, such as conditional comments again. However I chose to use a simple box model hack to fix this problem. The code for the hack looks like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> html <span style="color: #cc00cc;">#box</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
  w\idth<span style="color: #00AA00;">:</span> <span style="color: #933;">180px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>The * html makes this rule visible to <em>only</em> Internet Explorer. However this is not enough since the rules contained would be visible to <em>all</em> versions of IE, including IE 6 which doesn&rsquo;t have the problem. This is where the backslash comes into play. The code with the backslash rule is <em>not seen</em> by IE 5, but is by IE 6, meaning we can set the value for old versions, then reset for IE6.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> html <span style="color: #cc00cc;">#box</span> <span style="color: #808080; font-style: italic;">/*Rules for IE only*/</span>
<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">260px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*rule for IE 5 and below*/</span>
  w\idth<span style="color: #00AA00;">:</span> <span style="color: #933;">228px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*Rule for IE 6*/</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>Bug conclusion</h3>
<p><strong>Difficulty rating:</strong> 4/10 <strong>Annoyance factor:</strong> 8/10</p>
<h2>Bug #9 &#8211; Inline list of items</h2>
<p>This one drove me mad, I found this later on in testing IE 6, when I thought I was done.</p>
<p>It seemed that my list for post options (read more, comments, digg etc) would wrap partly around, leaving behind the background items and half the text.</p>
<p>The icons were done by adding a background image to the span of text, with a padding-left. This was to make the icon centred next to the text correctly.</p>
<p>To fix this I tried white-space:nowrap to the spans, this stopped the text from breaking up, but still left the icon behind. I think this was do to the padding staying where the box wrapped from, and not from its new position.</p>
<p>The fix? I ended up having to surround the spans with the background image icons, with a second span that had position:relative; so that the padding of the contained span would be relative to the new position. I called the outer span &#8216;wrapper&#8217;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">.wrapper<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>  <span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span><span style="color: #993333;">nowrap</span><span style="color: #00AA00;">;</span>  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3><span class="strike">Bug conclusion</span></h3>
<p><span class="strike"><strong>Difficulty rating:</strong> 7/10</span> <span class="strike"><strong>Annoyance factor:</strong> 9/10</span></p>
<h3>Complications of my fix</h3>
<p>It seems that, whilst working in IE 6, this fix made my icons overlap the text in IE 5/5.5, so to rectify this I added a conditional comment that targets IE 5 only, to give the span with the image a large width, making it display without overlap. It doesent look the same, however it makes it useable so is a good solution.</p>
<p>The code below is what i used, note the &#8216;lte&#8217; before the version of IE, this means &#8216;less than or equal to&#8217;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!--[if lte IE 5.5000]&gt;
      &lt;style&gt;
        .moretext{padding-left:32px;width:200px;}
     &lt;/style&gt;
&lt;![endif]--&gt;</pre></td></tr></table></div>

<h3>Bug conclusion</h3>
<p><strong>Difficulty rating:</strong> 8/10 <strong>Annoyance factor:</strong> 10/10</p>
<p>And so you have it, if you took the time to read this you will understand why it was all so frustrating, but in the end it was worth it.</p>
<p>If you have any improved solutions to any of these bugs, or your own bugs and solutions, feel free to post them as a comment,<br />
I&rsquo;m always willing to learn from others!</p>
<p>If you spot any bugs feel free to tell me, just note it may make my head implode!</p>
<img src="http://blue-anvil.com/7dc46085/266bbf6b/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></content:encoded>
			<wfw:commentRss>http://blue-anvil.com/archives/my-day-of-buggy-hell-with-ie-a-css-story/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
