I came up with a solution that seems like a good compromise. This is based on the fact that setting the border to <ul> solves the problem, while the margin-bottom element of the pre-sibling level block element obviously calls it.
Thus, setting border-top: 1px solid transparent; <ul> shifts it by one pixel, which is good with me. Since BalusC rightly points to comments, setting margin-top: -1px; will counteract bias.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Test</title> <style type="text/css"> ul { padding: 0; margin: 0; border-top: 1px solid transparent; list-style-type: none; } ul li { float: left; width: 140px; background-color: red; } div { clear: left; background-color: red; } </style> </head> <body> <h1>Heading 1</h1> <ul> <li>bla 1</li><li>bla 2</li><li>bla 3</li> </ul> <div>yada</div> </body> </html>
I admit that this is also hacking; he must remember what the dummy border is for, which is not much better than regular CSS tricks (but not much).
Previous version of the answer: I fixed it as it is now (it seems to work in browsers and does not require CSS hacking)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Test</title> <style type="text/css"> div.t ul { padding: 0; margin: 0; list-style-type: none; } div.t ul li { float: left; width: 140px; background-color: red; } div.c { background-color: red; } </style> </head> <body> <h1>Heading 1</h1> <div class="t"> <ul> <li>bla 1</li><li>bla 2</li><li>bla 3</li> </ul> <br style="clear: left;"> </div> <div class="c">yada</div> </body> </html>
I do not really like this solution, because it requires additional elements. But I don't like CSS dirty tricks anymore.
source share