IE6 Background Image Problem
3
Imagine that you have a blog and you are designing a new rating system where you will use the golden stars to rate your entries, so you make an HTML prototype to create the layout of your new rating system. Here is the code you have written:
1 <html>
2 <body>
3 <h1>
4 <div id="stars">
5 </div>
6 How is the BG IMG fixed in IE
7 </h1>
8 </body>
9 <style>
10 #stars{
11 height: 20px;
12 width: 100px;
13 float: right;
14 background: url("star_on.png") repeat;
15 }
16 </style>
17 </html>
The "star_on" image you are using is 20 x 20 px, the height of the stars' DIV is 20px to fit with the image, image is set to repeat, and the width is set to 100px so that you will see 5 stars.
So far we have done the coding; the next step is to test this on the browsers to be supported. It works well with different browsers ( tested on safari, opera, FF and chrome ) and here is how it is displayed:

When the turn came for testing this with IE and its unique rendering engine, it decided to render the markup as seen below:
![]()
Note that the problem is that the image is repeated vertically and goes beyond the 20px high DIV it should display within.
Let's start with the fix and then see why IE decided to extend the image.
The fix is to adjust the font-size property for the rating DIV :
1 #stars{
2 height: 20px;
3 width: 100px;
4 float: right;
5 background: url("star_on.png") repeat;
6 font-size: 1pt;
7 }
But how on earth is the font-size related to the BG image ?!
In fact, the problem is that when IE passes by an empty DIV in the markup, it assumes a non-breaking-space ( ) inside the DIV, then accordingly it applies to it the nearest inherited font size - in our case the H1 font-size, which is larger than the 20px height so the BG image found some more space to sneak into.
So in order to solve this, you have to override this font-size and adjust it to have your background image displayed correctly.
Written By:
Michael Youssef (blog.michaeleee.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!

