homepage Welcome to WebmasterWorld Guest from 54.205.241.107
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

    
Box model: lost parent element scrollbar
Rain_Lover



 
Msg#: 4516196 posted 6:50 am on Nov 6, 2012 (gmt 0)

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!

 

seoskunk



 
Msg#: 4516196 posted 12:47 am on Nov 8, 2012 (gmt 0)

Works for me

lucy24

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



 
Msg#: 4516196 posted 2:06 am on Nov 8, 2012 (gmt 0)

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 ::

Rain_Lover



 
Msg#: 4516196 posted 3:36 am on Nov 8, 2012 (gmt 0)

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.

lucy24

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



 
Msg#: 4516196 posted 5:17 am on Nov 8, 2012 (gmt 0)

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.

Rain_Lover



 
Msg#: 4516196 posted 6:10 am on Nov 8, 2012 (gmt 0)

Thanks for the tests!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved