html - Why do a div and a table behave differently when given width=100% here? -
here's code, reduced relevant parts:
<html><head><title></title> <style type="text/css"> body { background-color: #fff; } #titlebar{ border: solid 1px black; margin:10px; } #bodywrapper{ float: left; width: 100%; } #bodycolumn{ margin-left: 230px; height:500px; } #menucolumn{ float: left; width: 230px; border: solid 1px black; margin-left: -100%; height:500px; } .bigcontent{ width: 100%; margin:10px; } .section{ border: 1px solid black; padding:10px; overflow: auto; } </style></head><body> <div id="titlebar">title</div> <div id="bodywrapper"><div id="bodycolumn"> <table class="section bigcontent"><tr><td>first</td></table></table> <div class="section bigcontent">second</div> </div></div> <div id="menucolumn">menu</div> </body></html>
my problem:
- the
<div>
containing "second" wider<table>
containing "first" although both siblings , havewidth=100%
via same css class - the
<div>
wider screen, causing scrollbars appear
why , can fix it?
note: seeing same problems in both firefox 3.6 , ie 8
this because of padding
. in css, width property applies content box of elements, without padding.
see http://www.w3.org/tr/css21/box.html : width
property applies content
block in following schema:
so outer element's width 100% of parent's width, plus 10px of left padding , 10px of right padding.
given element block element, should not necessary specify width 100%.
so solutions are:
- to not set width
- to take padding account when setting width (here require set padding in
%
, e.g. 2% of padding , width of 96% (100-2*2)
Comments
Post a Comment