html - 2 column layout (Left column fixed width, right fluid + clear:both) -
just need have been trying sort out ages now. need:
i've got 2 column layout, left column has fixed width 220px , right column has fluid width.
code is:
<!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> <title>fluid</title> <style type="text/css" media="screen"> html, body { background: #ccc; } .wrap { margin: 20px; padding: 20px; background: #fff; } .main { margin-left: 220px; width: auto } .sidebar { width: 200px; float: left; } .main, .sidebar { background: #eee; min-height: 100px; } </style> </head> <body> <div class="wrap"> <div class="sidebar">this static sidebar</div> <div class="main">this main, , fluid div</div> </div> </body> </html>
there's no problem @ all. when use css syntax clear: both in right column, content after gets moved under left column. right behaviour , nothing against it.
but relly need use clear: both in way, stays in context of right column (doesn't affected left column @ all, , doesn't move underneath)
is there simple around retaining basic float concept of page design?
update: please see link know i'm on may bit confusing description. link: http://jsfiddle.net/k4l5k/1/
here's altered css:
html, body { background: #ccc; } .wrap { margin: 20px; padding: 20px; padding-right:240px; background: #fff; overflow:hidden; } .main { margin: 0 -220px 0 auto; width: 100%; float:right; } .sidebar { width: 200px; float: left; height: 200px; } .main, .sidebar { background: #eee; min-height: 100px; } .clear { clear:both; } span { background: yellow }
basically i've done change way layout done, .main
div floated on right. this, had add 2 things:
- a padding of 240px on
.wrap
div, , - a right margin on
.main
div of -220px align fluid part of page.
because we've floated .main
div on right, clear: both;
affects content inside .main
div, want.
you can see demonstration here: http://jsfiddle.net/6d2qf/1/
Comments
Post a Comment