Internet Explorer Double Margin Bug

Posted by: webmaster in transparencyInternet ExplorerimagesCSS on  

A while ago I wrote this article about transparency in internet explorer 6. This was just one of many problems with browser compatibility that can hit you when you design a Joomla template. This article is about another such problem: the so called 'double margin bug of internet explorer'. If you see that your Joomla site looks good in Firefox or the brand new Google Chrome browser, but in internet explorer you see that some parts are not at the right place, like there is a double margin, then you've come accross this bug.

 

 

What it is

 

The bug happens if you your site meets following conditions:

 

  • You have a div with the css property float:left
  • This div is inside another div
  • This floating div has a margin at the left

 

If these conditions are met, then you will have the double margin bug. If you create tableless templates (like you should), then there's a good chance you'll see this problem sooner or later.

 

Example

 

Let's show this with an example. If your code looks like this:

 


 

div.wrap {
width: 100%;
}
div.main {
float: left;
width: 100px;
height: 100px;
margin-left: 100px;
}

 

In browsers that work correctly, this will look like this:

Double Margin Bug in Joomla Templates

 

In internet explorer however you will get something like this:

Double Margin Bug in Joomla Templates

 

Of course this can mess up your design completely. Luckily, the solution is quit simple

 

The Solution

 

Internet explorer will add the margin as expected to the div element. However, internet explorer will look what the display property is and this will add the margin a second time. Now you know how the bug is caused, it's probably not that difficult anymore to guess how to solve it. Simply adding the display:inline property to the div will solve the problem. So the code will look like this:

 

 

div.wrap {
width: 100%;
}
div.main {
float: left;
width: 100px;
height: 100px;
margin-left: 100px;
display:inline;
}

 

Now your Joomla template design will look again the same in all browsers. Speaking of Joomla templates: if you're new to creating Joomla Templates, then keep an eye on our site as we're currently working on an article series to explain in detail where to start if you want to create your own template.

Trackback(0)
Comments (9)Add Comment
Header width problem

written by Meanne, November 19, 2008
the width of my header (its an image )differs from Firefox 2.0.0.14 and 3.0.4. and Internet Explorer..Can you help me with this..
...

written by Largo, November 21, 2008
With this little information, I can't help you. A linnk to the site where you have the problem would be nice
ie6 double margin bug

written by Alessandro, April 19, 2009
Instead of using display:inline there is an easier and safer solution: using this simple js bug fix http://www.programmatorephp.it...n-hack.php
Other solutions have some side effects.
thanks dudue

written by hassan, May 27, 2009
its great i solve my problem with this code thanks dudesmilies/grin.gif
Real Estate template

written by Lou, June 17, 2009
I installed the Real Estate template here, http://southwest-environmental.com/
The template on shows on the main page,I try a menu link and I get white page.
Thanks
LMan
...

written by Largowww, June 19, 2009
I see the problem is solved.
...

written by Lou, June 19, 2009
Thank you very much for your help.smilies/cool.gif
...

written by Trevor Smith, July 06, 2009
That Internet Explorer Double Margin Bug sounds like one mean critter.

Hope it doesn't get on my website. All those people who've made a small fortune after signing up for my free newsletter are going to be really upset!

Thank you!!!!!

written by Darren H, October 21, 2009
Thank you thank you thank you!! Never had this issue before, until working on my current site where I needed to shift everything over 200px to make room for a consistent graphic on the left. Got it how I wanted in every browser apart from IE6, but I have now thanks to that extra little line of code. Tried a number of pointless workarounds, but this seems to do the trick, Many thanks once again smilies/cheesy.gifsmilies/grin.gif

Write comment

security code
Write the displayed characters


busy