i am trying to spread 4 items evenly across its parent container but for some reason in ie7 the fourth item is pushed onto the next line. I don’t understand how that’s possible if I am specifying 25% width for each item. Here is my html/css:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
html, body, ul, li { padding:0; margin:0; }
ul { list-style:none outside none; }
ul li { float:left; height:40px; width:25%; }
ul li a { display:block; height:20px; padding-top:20px; text-align:center; }
</style>
</head>
<body>
<div style="overflow:hidden">
<ul>
<li><a href="a">A</a></li>
<li><a href="b">B</a></li>
<li><a href="c">C</a></li>
<li><a href="d">D</a></li>
</ul>
</div>
</body>
</html>
Seems to work fine in other browsers, but not ie7.
See this question. Basically IE rounds up when you use percentage widths so it’s possible to go over 100% where it will just bump your last item down. So to fix that you should either use 24% instead of 25% or just figure the right px width.
It’s a
bitlot less nice but you could change your code like so:CSS
HTML
which works for me in IE7 and Chrome