Consider the following HTML markup. In most browsers that I have tested, the second list is displayed differently (each list item is indented).
The only difference between the two lists relates to the CSS font-style property, which I would not expect to change the list layout. Is there a explanation for this behavior?
<!DOCTYPE html>
<html>
<head>
<style>
body {font-family: sans-serif}
span {float: left}
ul.bad span {font-style: italic}
</style>
</head>
<body>
<ul>
<li><span>foo</span></li>
<li><span>foo</span></li>
<li><span>foo</span></li>
<li><span>foo</span></li>
</ul>
<ul class="bad">
<li><span>foo</span></li>
<li><span>foo</span></li>
<li><span>foo</span></li>
<li><span>foo</span></li>
</ul>
</body>
</html>
The span
spanwith the straight text becomes 18 pixels in height, while the italic text forces thespanto 19 pixels.This causes a slightly different behaviour when using
float: left.a quick fix would be to set the
line heightproperty equal for both span types:not regarding the intentions of your code 😉