Vertical-Align:middle NOT Working in IE6

I just tried to align a image next to a button, it worked perfectly in FF and IE7 / 8, but the image isn't aligned in IE6.

I fully understand that vertical-align only works properly on inline elements, so no DIV is used. Please see the code below :

Is this a normal behavior in IE6? If so, are there any workarounds?

This article used the same method (vertical-align:middle) in one of the samples, but it worked in IE6!

http://phrogz.net/CSS/vertical-align/index.html
<input type="button" class="submit" id="submit" value="Submit" onClick="postForm();" />
<img src="123.gif" id="loading" style="vertical-align:middle;" />

Open in new window

ChiehkaiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

level9wizardCommented:
Likely a much quicker/cleaner approach would be to use ling-height property to position this centered vertically. However, take a look at this article:
http://www.jakpsatweb.cz/css/css-vertical-center-solution.html
0
ChiehkaiAuthor Commented:
Yep.. I already tried the code in this article but it didn't work in IE6 either...
0
LZ1Commented:
Unfortunately good old IE 6 hates CSS.  Can I ask why you are supporting it?  

Your going to have to wrap it in a div and then specify line-height, font size, height for the div as well as the image dimensions.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style> 

div{
	height:200px;
	width:200px;
	background:blue;
	text-align:center;
	line-height:200px;
	font-size:200px
}
*>div{
	font-size:12px
}
img{
	vertical-align:middle;
}

</style>

</head>

<body>
  	

<input type="button" class="submit" id="submit" value="Submit" onClick="postForm();" /><br /> 
<div >
<img src="123.gif" name="loading" width="300" height="200" id="loading"  />
</div>
</body>
</html>

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

ChiehkaiAuthor Commented:
Well I hope to support as much browsers as possible.

Also, if the button & img tags aren't in the same div, the image will be displayed under that button, not beside (right next to) it.

Something that I don't understand, why could the article I provided above was able to make it work in IE6 with the exact same command (vertical-align:middle;) that I used which had failed?
0
LZ1Commented:
Some friendly advice regarding IE 6: We must allow it to die.  People need to upgrade their browsers as it's over 10 years old now.  I understand people may need it for legacy applications and the like, but mainstream sites and companies are moving away from it.  IE 6 wastes precious time and resources when developing for it.  
Ok, I'm off my soap box now. :)  
If your still with me, the image has to have something to be vertically aligned too.  If you just put it out there and say vertically align, it won't do anything.  If it's inside an inline or block element you shouldn't have a problem.  That's why we thew the div in there.  You can enclose them in a <p> tag as well and it will work.

 <p><input type="button" class="submit" id="submit" value="Submit" onClick="postForm();" /> 
<img src="1154337_leather.jpg" width="150" height="100" style="vertical-align:middle;" />  <br /> <br /> </p>

Open in new window

0
remorinaCommented:
Hi,
I doubt this would be a normal behaviour, I've checked it in IE6 and it seems to work just fine, I've tried more than 1 version of IE6, as well as xenocode standalone http://www.spoon.net/IE6 and IE Tester and they all seem to work ok

I've also uploaded an example for you to check if it works with your browser or not here
http://remorina.com/1/ee/imgvalign.htm 

imgvalign-ie6.jpg
0
ChiehkaiAuthor Commented:
yes, your page is working when I viewed it in IE6...

Quite strange, probably some conflict with that in IE6? I tried to remove all CSS codes but its still not aligned properly in IE6.

LZ1, thanks for the information. I know IE6 is already a rather old browser, but its still quite widely used. Up to 30% of my total IE visitors use IE6, only 20% use IE7 & over 50% on IE8.
0
ChiehkaiAuthor Commented:
ah.. I think that's because the image I'm using is smaller than the button itself. Try using a 16x16 image, and see if you can get it aligned properly in IE6.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
</head>
<body>
    <input type="button" class="submit" id="submit" value="Submit" onClick="postForm();" />
    <img src="images/16x16.gif" id="loading" style="vertical-align:middle;" />
</body>
</html>

Open in new window

0
remorinaCommented:
I think your problem lies in the font size not the image align.
When the image size is small IE6 gets affected with the container's font size, especially with lower values making the image align towards the bottom.

I've updated the example in http://remorina.com/1/ee/imgvalign.htm to demonstrate.

You need to adjust the font-size to the div or container of your button and image, but keep in mind that you might not get the exact output among all browsers it will only help you to make it better, note that line-height might not work properly.

In the updated example, both 1st and second rows of the button and image have nothing different except a font-size style, note how it affects IE6 drastically while not haing that much effect in other browsers especially with the 1st one

I hope this makes it easier to understand and fix

imgvalign-ie6.jpg
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.