Welcome to WebmasterWorld Guest from 50.16.78.128

Forum Moderators: not2easy

Message Too Old, No Replies

Box model: lost parent element scrollbar

   
6:50 am on Nov 6, 2012 (gmt 0)

5+ Year Member Top Contributors Of The Month



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!
12:47 am on Nov 8, 2012 (gmt 0)

WebmasterWorld Senior Member Top Contributors Of The Month



Works for me
2:06 am on Nov 8, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



By "correctly" do you mean that it shows them at all?

The answer is almost certainly browser-specific.

I too got different results in both www preview (Webkit-based) and Camino ("Firefox Lite").

Apparently overflow is calculated differently for height and width. For height, <=101 px counts as overflow. For width it's <=100. You can see it clearly by setting the other property to 110 and just changing one.

:: will return to play around more, but no time now ::
3:36 am on Nov 8, 2012 (gmt 0)

5+ Year Member Top Contributors Of The Month



By "correctly" do you mean that it shows them at all?


Yes -- when the child height (102px) is larger than the parent height (101px) the scrollbar(s) appear.
5:17 am on Nov 8, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



As promised, I came back and did more testing. And as I suspected, it's browser-dependent.

I kept the "child" at 100px square, and fiddled with the "parent".

Webkit (Safari, Chrome) and Mozilla (Firefox): minimum size to avoid overflow is width 101, height 102. I do not pretend to understand this, but them's the numbers.
Opera: 101 for both
MSIE 5 pause for hysterical laughter: 100px for both

The scrollbar itself is probably OS-dependent. On my system it's 15 pixels wide, so that's how much you have to add to the parent in order to keep both sides from jumping to a scroll bar as soon as one side becomes too short.
6:10 am on Nov 8, 2012 (gmt 0)

5+ Year Member Top Contributors Of The Month



Thanks for the tests!