{"id":145,"date":"2009-07-19T08:54:39","date_gmt":"2009-07-19T07:54:39","guid":{"rendered":"http:\/\/www.simonbattersby.com\/blog\/?page_id=145"},"modified":"2010-11-01T13:47:43","modified_gmt":"2010-11-01T12:47:43","slug":"ie6-and-the-3px-bug","status":"publish","type":"page","link":"https:\/\/www.simonbattersby.com\/blog\/ie6-and-the-3px-bug\/","title":{"rendered":"IE6 and the 3px bug"},"content":{"rendered":"<p>Let&#8217;s assume I&#8217;m building a simple 2 column layout. I want my left column to be 200px wide and my right column to be 600px wide, so they sit next to each other in an 800px wide wrapper. My html might look like this:<\/p>\r\n<pre>&lt;div id=\"wrapper\"&gt;\r\n&lt;div id=\"left\"&gt;&lt;\/div&gt;\r\n&lt;div id=\"right\"&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\r\n\r\n<p>and my css might look like this:<\/p>\r\n\r\n<pre>#wrapper {width:800px}\r\n#left{float:left;width:200px;height:100px;background-color:red}\r\n#right{margin-left:200px;width:600px;height:100px;background-color:blue}<\/pre>\r\n\r\n<p>So this should be fine because 200px+600px=800px and the two columns fit neatly and precisely within #wrapper. So in IE7, IE8, Firefox 2, Firefox 3, Chrome, Safari4 and Opera 9 it will look like this:<\/p>\r\n\r\n<img loading=\"lazy\" decoding=\"async\" title=\"Red and blue divs side by side\" src=\"\/images\/guides\/ie6_3px\/3px_Firefox.jpg\" alt=\"Red and blue divs side by side\" width=\"518\" height=\"140\" \/>\r\n\r\n<p>But IE6 adds an extra 3px gap to the right of #left, leaving only 597px for #right to fit in. #right is too big, so the whole of #right drops &#8211; &#8220;float drop&#8221; &#8211; and your nice design&#8217;s a disaster. Like this:<\/p>\r\n\r\n<img loading=\"lazy\" decoding=\"async\" title=\"Blue div below and to the right of red div\" src=\"\/images\/guides\/ie6_3px\/3px_IE6.jpg\" alt=\"Blue div below and to the right of red div\" width=\"518\" height=\"217\" \/>\r\n\r\n<p>This is a particularly cunning bug, in my opinion, since in this circumstance the dropped element then sits right up against the floated one and there&#8217;s no obvious gap and no clue as to why it&#8217;s all gone wrong. There&#8217;s a couple of solutions, fortunately.<\/p>\r\n\r\n<p>If your design allows it, the easiest fix is to just remove the width from #right and allow it to effectively be a bit narrower in IE6 than in everything else. This won&#8217;t work in lots of cases if you&#8217;re using background colours or images, however. It wouldn&#8217;t work in my example above because there would be a 3px white gap between the two columns. In this case the best solution I&#8217;ve found is to float <em>both columns<\/em>, so my example css becomes:<\/p>\r\n\r\n<pre>#wrapper {width:800px}\r\n#left{float:left;width:200px;height:100px;background-color:red}\r\n#right{float:right;width:600px;height:100px;background-color:blue}<\/pre>\r\n\r\n<p>There may be times when you can&#8217;t float both columns, for example if the right column has a fluid width. In this case the problem can be tackled with conditional comments for IE6 only. A 3px <em>negative<\/em> margin needs to be applied to the floated element, <em>and<\/em> the margin on the non-floated element needs to be reduced by 3px to match. So, my example css becomes:<\/p>\r\n\r\n<pre>#wrapper {width:800px}\r\n#left{float:left;width:200px;height:100px;background-color:red}\r\n#right{margin-left:200px;height:100px;background-color:blue}<\/pre>\r\nThis will apply to all browsers, but I&#8217;ll target IE6 with this css as well:\r\n<pre>&lt;!--[if IE 6]&gt;\r\n&lt;style type=\"text\/css\"&gt;\r\n#left{margin-right:-3px}\r\n#right{margin-left:197px}\r\n&lt;\/style&gt;\r\n&lt;![endif]--&gt;<\/pre>\r\n\r\n<p>I&#8217;ve created a demo page <a title=\"Demo page for IE6 3px bug\" href=\"\/demos\/ie6_3px_demo.htm\">here<\/a>, if you want to see this for yourself.<\/p>","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s assume I&#8217;m building a simple 2 column layout. I want my left column to be 200px wide and my right column to be 600px wide, so they sit next to each other in an 800px wide wrapper. My html might look like this: &lt;div id=&#8221;wrapper&#8221;&gt; &lt;div id=&#8221;left&#8221;&gt;&lt;\/div&gt; &lt;div id=&#8221;right&#8221;&gt;&lt;\/div&gt; &lt;\/div&gt; and my css might [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-145","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages\/145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/comments?post=145"}],"version-history":[{"count":0,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/pages\/145\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/media?parent=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}