Results 1 to 8 of 8

Thread: Why is this padding expanding my div?

  1. #1
    Join Date
    Aug 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why is this padding expanding my div?

    First of all, here's my code. It validates and all that jazz:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<link href="style.css" rel="Stylesheet" type="text/css" />
    	<title>CSS Test</title>
    </head>
        <body>
    		<div id="menu">menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu</div>
    		<div id="wrapper">
    			<div id="tree">tree</div>
    			<div id="input">input</div>
    			<div id="description">description</div>
    		</div>
        </body>
    </html>
    Code:
    * {
    	margin: 0;
    	padding: 0;
    }
    
    #wrapper {
    	width: 100%;
    	height: 100%;
    	z-index: 0;
    	position: absolute;
    	top: 0px;
    	right: 0px;
    }
    
    #menu {
    	width: 100%;
    	height: 100px;
    	background-color: #ffff00;
    	border: 0px;
    	z-index: 1;
    	position: absolute;
    }
    
    #tree {
    	float:left;
    	width: 30%;
    	height: 100%;
    	background-color: #008000;
    	border: 0px;
    	z-index: 0;
    	position: absolute;
    	padding-top: 100px;
    	top: 0px;
    	left: 0px;
    }
    
    #input {
    	width: 70%;
    	height: 70%;
    	float: right;
    	background-color: #ffa500;
    	overflow: auto;
    	border: 0px;
    	z-index: 0;
    	padding-top: 100px;
    }
    
    #description {
    	width: 70%;
    	height: 30%;
    	float: right;
    	background-color: #add8e6;
    	overflow: auto;
    	border: 0px;
    	z-index: 0;
    }
    The goal here is to have a fixed height menu at the top of the page, and everything else be percentages and no scrolling in the window. That part works fine, and I did it with z-indexes. The problem, though, is that the padding-top in the menu and input divs to make their content visible below the menu makes the div bigger instead of just pushing the content down. This forces the user to have to scroll, and I don't want that. What should I do?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Generally, that's what padding does. It adds to the physical dimension of the element. Since you are already using so much absolute positioning (something that generally makes it hard to design a flexible page, once actual content is added) you can just set the wrapper overflow to hidden:

    Code:
    #wrapper {
    	width: 100%;
    	height: 100%;
    	z-index: 0;
    	position: absolute;
    	top: 0px;
    	right: 0px;
    	overflow:hidden;
    }
    But I would recommend a complete redesign that doesn't use absolute positioning.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The absolute positioning is used correctly in this case, but I'd suggest using ems rather than pixels. As it stands, that menu is going to look awfully odd if the user's font doesn't fit inside it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey View Post
    The absolute positioning is used correctly . . .
    Perhaps, but not wisely. I never said there was anything invalid about it. It will make it difficult to load the normal sorts of content one often finds on pages into the design and have them displayed well under the variety of user end conditions/agents that exist on the web. If the design has a specialized use (such as limited amount of text only presentation), it may be appropriate.

    Any position property other than the default (static) should be used sparingly. Otherwise you get a rigid design that cannot adapt to varying conditions. It also can make it difficult to use positioning where it is the most beneficial - for special effects, and situations that may arise.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    The simple solution to stopping the div from getting bigger is by putting a div inside of it with a margin:

    Code:
    #tree {
    	float:left;
    	width: 30&#37;;
    	height: 100%;
    	background-color: #008000;
    	border: 0px;
    	z-index: 0;
    	position: absolute;
    	top: 0px;
    	left: 0px;
    }
    
    #tree_inside{
    margin-top: 100px;}
    HTML Code:
    <div id="tree">
         <div id="tree_inside">
              <!-- MENU CONTENT HERE -->
         </div>
    </div>
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by alexjewell View Post
    The simple solution to stopping the div from getting bigger is by putting a div inside of it with a margin:

    Code:
    #tree {
    	float:left;
    	width: 30&#37;;
    	height: 100%;
    	background-color: #008000;
    	border: 0px;
    	z-index: 0;
    	position: absolute;
    	top: 0px;
    	left: 0px;
    }
    
    #tree_inside{
    margin-top: 100px;}
    HTML Code:
    <div id="tree">
         <div id="tree_inside">
              <!-- MENU CONTENT HERE -->
         </div>
    </div>
    Hey, that does work well!

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<title>CSS Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <style type="text/css">
    * {
    	margin: 0;
    	padding: 0;
    }
    
    #wrapper {
    	width: 100%;
    	height: 100%;
    	z-index: 0;
    	position: absolute;
    	top: 0px;
    	right: 0px;
    	overflow:hidden;
    }
    
    #menu {
    	width: 100%;
    	height: 100px;
    	background-color: #ffff00;
    	border: 0px;
    	z-index: 1;
    	position: absolute;
    }
    
    #tree {
    	float:left;
    	width: 30%;
    	height: 100%;
    	background-color: #008000;
    	border: 0px;
    	z-index: 0;
    	position: absolute;
    	top: 0px;
    	left: 0px;
    }
    
    #tree_inside, #input_inside {
    margin-top: 100px;
    }
    
    #input {
    	width: 70%;
    	height: 70%;
    	float: right;
    	background-color: #ffa500;
    	overflow: auto;
    	border: 0px;
    	z-index: 0;
    }
    
    #description {
    	width: 70%;
    	height: 30%;
    	float: right;
    	background-color: #add8e6;
    	overflow: auto;
    	border: 0px;
    	z-index: 0;
    }
    </style>
    </head>
        <body>
    		<div id="menu">menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu</div>
    		<div id="wrapper">
    			<div id="tree"><div id="tree_inside">tree</div></div>
    			<div id="input"><div id="input_inside">input</div></div>
    			<div id="description">description</div>
    		</div>
        </body>
    </html>
    But, there will still be the problems I mentioned before.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I never said there was anything invalid about [using absolute positioning]. It will make it difficult to load the normal sorts of content one often finds on pages into the design and have them displayed well under the variety of user end conditions/agents that exist on the web.
    Not when used correctly, as here.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey View Post
    Not when used correctly, as here.
    We'll see, the page (as near as I can tell) cannot expand beyond the window.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •