How to Avoid the IE Box Model bug
3
One of the common bugs of IE is the box model bug which affects the box model of any HTML block-level element when the page is in quirks mode. In brief, IE includes the padding when calculating the width of the block. Personally, I found this very logical and I don't like to consider it a bug, but since it violates the W3C standards, it is a bug.
One simple approach to avoid this bug is to avoid specifying both width and padding or border for an element. How?
Say you have a sidebar block for which you need to specify a width, a border and a padding.
<style type="text/css">
#sidebar {
background-color: #CCCCCC;
padding: 5px;
width: 183px;
border: 1px solid #000000;
}
</style>
<div id="sidebar">Content for sidebar goes here.</div>
Here is the result in Firefox and IE:
To avoid the bug, you can simply add a child block to the sidebar. Then, specify the width for the sidebar and specify the border and padding for the child block.
<style type="text/css">
#sidebar {
background-color: #CCCCCC;
width: 183px;
}
#sidebar_content {
padding: 5px;
border: 1px solid #000000;
}
</style>
<div id="sidebar">
<div id="sidebar_content">Content for sidebar goes here.</div>
</div>
Now, you get the same results for both Firefox and IE with exactly the same width you specified in your CSS code.
Written by:
Hatem Mahmoud (www.expressionlab.com)
Comments
Post a Comment
eSpace podcast Prodcast
Archive
- September 2011
- April 2011
- March 2011
- December 2010
- November 2010
- September 2010
- August 2010
- July 2010
- June 2010
- April 2010
- March 2010
- November 2009
- October 2009
- September 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- November 2008
- October 2008
- September 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- January 2008
- April 2007
- March 2007
Latest Comments
- SpectraMind Commented on Egypt Wins UK's National Outsourcing Association Award
- Rofaida Awad Commented on Go Egypt Go!
- Different Mike Commented on Only idiots change their iPhone root password!
- Mike Commented on Only idiots change their iPhone root password!
- smile Commented on Only idiots change their iPhone root password!

