I offer 2 options for solving your question ( to work correctly in all browsers, you need to change the encoding ): First method : almost exactly what you wanted to implement initially was implemented, so:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org /TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ru"> <head> <title>Блоки</title> <meta http-equiv="Content-Type" content="text/html; charset:windows-1251"/> <style type="text/css"> html, body { width: 1000px; height: 700px; } div#main { width: 500px; border: 1px solid black; } div#left { width: 100px; height: auto; border: 1px solid green; } div#right { width: 100px; height: auto; border: 1px solid red; margin-left: 398px; } </style> </head> <body> <div id="main"> <div id="left">Лево-вверх</div> <div id="right">Право-низ</div> </div> </body> </html>
The height of the blocks is built depending on the height of the contents. and the height of the “main” container varies depending on the height of the left and right blocks contained in it. What was the problem : misunderstanding of the concepts of auto
and 100%
. Sometimes the browser considers these concepts identical. All the more, if you do not specify absolute dimensions anywhere (at least for the width and height of the whole page). I have somehow described this situation in which of the questions for example in this . You can read if interested. In addition, the use of absolute dimensions helps to avoid a large number of IE block-model interpretations by browsers, because after setting the width or height, the element has the property hasLayout and the browser practically stops to naughty. In this case, the browser understands width: auto
for the right
block as “occupy 100% of the width of the parent block”. Tip : do not hesitate to absolute size. Even if you want to implement a rubber layout.
The second way :
The second method already implements my idea with a floating model.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ru"> <head> <title>Блоки</title> <meta http-equiv="Content-Type" content="text/html; charset:windows-1251"/> <style type="text/css"> html, body { width: 1000px; height: 700px; } div#main { width: 500px; height: 300px; border: 1px solid black; } div#left { width: 100px; height: auto; border: 1px solid green; float: left; } div#right { width: 100px; height: auto; border: 1px solid red; float: right; margin-top: 278px; } </style> </head> <body> <div id="main"> <div id="left">Лево-вверх</div> <div id="right">Право-низ</div> </div> </body> </html>
Since in a floating model, floating blocks are “retrieved” from the normal flow, it is better to set the fixed height of the parent block for correct operation. Well, in order to “press” the right block to the bottom - we increase the top margin by the required number of pixels (including, for this, it is necessary to know the height of the parent block). It is worth noting : for normal operation in IE browsers, the presence of a so-called "cleansing" element is necessary. for it you must specify the property clear: both
. For this browser, his own way understands this model.
Here, it seems, and everything that I wanted to write! I hope I managed to help you and am grateful for the voices))))