Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Collapsing Margins?

    Hello,

    I was wondering what you would call the following effect, I thought af first this might be the effect of "collapsing margins", but now I'm not sure.

    Example 1) When I inculde <br class="boundary" /> as below:

    + the green #wrapper's min-height:100% fills the page
    + the yellow #content's bottom-margin doesn't trigger a scrollbar effect

    Example 2) When I omit <br class="boundary" />:

    + the green #wrapper starts at the top of #content, ignoring its margin-top
    + the yellow #content's bottom margin triggers a scrollbar effect

    This is my goal:

    + to have green #wrapper's min-height fill the page
    + to have yellow #content's margins trigger scrollbar effects
    + achieve these effects with CSS and not by adding the <br>

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    html, body {
    	height: 100%;
    	margin: 0px;
    	padding: 0px;
    }
    #wrap {
    	background-color: #009999;
    	min-height: 100%;
    }
    #content {
    	padding: 50px;
    	background-color: #FFFFCC;
    	margin-top: 400px;
    	margin-right: auto;
    	margin-bottom: 400px;
    	margin-left: auto;
    	width: 400px;
    }
    .boundary {
    	height:0;
    	font-size: 1px;
    	line-height: 0px;
    }
    -->
    </style>
    </head>
    
    <body>
    <div id="wrap">
    	<br class="boundary" />
    	<div id="content">	
    		This is my example
    	</div>
    </div>
    
    </body>
    </html>
    Last edited by skibulk; 02-17-2011 at 08:50 PM. Reason: added [CODE] tags

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,749
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    Hello skibulk,
    Pretty sure it's collapsing margins you're seeing.

    Try it this way -
    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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    html, body {
    	height: 100%;
    	margin: 0px;
    }
    #wrap {
    	min-height: 100%;
    	margin: 0; 
    	overflow: auto;
    	background: #009999;
    }
    #content {
    	width: 400px;
    	margin: 400px auto;
    	padding: 50px;
    	background: #ffffcc;
    }
    </style>
    </head>
    <body>
        <div id="wrap">
            <div id="content">	
            	This is my example
            <!--end content--></div>
        <!--end wrap--></div>
    </body>
    </html>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #3
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks,

    That worked for firefox, but I'm not seeing it at all in IE8.
    also,
    margin: opx;

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,749
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    Quote Originally Posted by skibulk View Post
    Thanks,

    That worked for firefox, but I'm not seeing it at all in IE8.
    also,
    margin: opx;
    No, it was the <!-- at the top. You had them and I thought I edited them out...


    I do type very fast and sometimes hit a o instead of a 0 but I didn't this time. If I did, where?
    That line should be margin: 0; anyway.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kansas, USA
    Posts
    487
    Thanks
    0
    Thanked 54 Times in 53 Posts
    @Excavator: I think skibulk was pointing out that omission of the 'px' unit on your declaration.

    @Skibulk: While it is very important to include units when declaring a length value, 0 is a special case. According to CSS Pocket Reference [O'Reilly] "... a value of 0 (zero) need not have a unit designator." In other words, 0px is the same as 0% is the same as 0em. Excavator's declaration was perfectly valid.


  •  

    Posting Permissions

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