Log in

View Full Version : Box model: lost parent element scrollbar



Rain Lover
11-06-2012, 06:42 AM
The first sample shows scrollbars correctly:


<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#parent {width:102px; height:101px; background:red; overflow:auto;}
#child {width:100px; height:100px; margin:1px; background:green;}
</style>
</head>
<body>
<div id="parent">
<div id="child"></div>
</div>
</body>
</html>

But the second doesn't:


<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#parent {width:101px; height:102px; background:red; overflow:auto;}
#child {width:100px; height:100px; margin:1px; background:green;}
</style>
</head>
<body>
<div id="parent">
<div id="child"></div>
</div>
</body>
</html>

Why is that?
Thanks!

CasJ
11-14-2012, 11:25 AM
If you adjust the width or height from the second example #child element the scrollbars will show.

This is because the margin is 1 pixel so the total width/height will be 102 pixels.