Hari's Corner
Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and thenCSS fix for bad layout alignment in Internet Explorer
Filed under:
Tutorials and HOWTOs by
Hari
Posted on Tue, Mar 6, 2007 at 16:43 IST (last updated: Wed, Oct 29, 2008 @ 21:58 IST)
<div>
element, the margin is calculated from the body's edge. This led to a weird problem where the width of the entire layout was shifted a lot more to the right than I intended.
I had used margin-left: 60px;
in the CSS of the main layout <div>
tags: the header, the content and the footer ids. And also used margin-left to create spaces to the left of the inside content element and the sidebar.
Here's how I fixed the bug to make it pixel correct in Internet Explorer.
- Removed the
margin-left
for each of the main CSS elements (the header, the content and the footer) and instead gave the<body>
element amargin-left
attribute with the same width to get the same result. The content block is shifted to the right by 60 pixels and doesn't stick to the left edge of the browser. - Replaced the inner
margin
attributes (for the inside content block as well as for the sidebar block) with thepadding
attribute to get the same gap.
margin
CSS attribute and so it makes some bizzare layout decisions when rendering the <div>
blocks.
Here are the explanatory screen shots:
Before the fix:After the fix:
The above fix should be applicable for CSS layout problems of this nature with IE while ensuring that other browsers also render correctly. There are other CSS rendering issues with Internet Explorer, but that's another story altogether
Comments closed
The blog owner has closed further commenting on this entry.
10 comment(s)
Comment by Dominic (visitor) on Tue, Mar 6, 2007 @ 19:18 IST #
Comment by hari (blog owner) on Tue, Mar 6, 2007 @ 19:20 IST #
Comment by Sudipta Chatterjee (visitor) on Wed, Mar 7, 2007 @ 09:02 IST #
Comment by hari (blog owner) on Wed, Mar 7, 2007 @ 09:17 IST #
Comment by J_K9 (visitor) on Thu, Mar 8, 2007 @ 13:22 IST #
Comment by hari (blog owner) on Thu, Mar 8, 2007 @ 14:22 IST #
Comment by J_K9 (visitor) on Thu, Mar 8, 2007 @ 18:58 IST #
Comment by hari (blog owner) on Thu, Mar 8, 2007 @ 20:51 IST #
Comment by J_K9 (visitor) on Sun, Mar 11, 2007 @ 19:14 IST #
Comment by hari (blog owner) on Sun, Mar 11, 2007 @ 20:37 IST #