Results 1 to 2 of 2

Thread: css: margin being applied to wrong element

  1. #1
    Join Date
    Jul 2009
    Posts
    1

    css: margin being applied to wrong element

    i am laying out a webpage via css and for some reason the 'margin-top' property that i added to one element is moving the entire page contents down. below is the code:
    ----------html-----------
    <body>
    <div id="wrapper">
    <div id="navigation"> <a href="index.html">home</a> <a href="news.html">news</a> <a href="portfolio.html">portfolio</a> <a href="recent.html">recent work </a> <a href="contact.html">contact</a> </div>
    <div id="content">
    <div id="contentBox">Content for id "contentBox" Goes Here</div>
    </div>
    <div id="footer">(c) 2009 evanfarinholt.com</div>
    </div>
    </body>

    ---------------css---------
    #wrapper {
    height: auto;
    width: 700px;
    margin-top: 35px;
    margin-right: auto;
    margin-bottom: 50px;
    margin-left: auto;
    }
    #wrapper #navigation {
    height: 22px;
    background-color: #000000;
    border-left-width: 3px;
    border-left-style: solid;
    border-left-color: #FFFFFF;
    }

    a {
    padding-left: 10px;
    padding-right: 10px;
    }

    a:link, a:visited {
    color: #FFFFFF;
    text-decoration: none;
    background-color: #000000;
    }

    a:hover, a:active {
    background-color: #FFFFFF;
    color: #000000;
    text-decoration: none;
    }

    #wrapper #bodyPic {
    height: 554px;
    }
    #wrapper #bottomContent {
    background-color: #000000;
    height: 150px;
    border-left-width: 3px;
    border-left-style: solid;
    border-left-color: #FFFFFF;
    }
    #wrapper #newsContent {
    height: 500px;
    border-left-width: 3px;
    border-left-style: solid;
    border-left-color: #FFFFFF;
    }
    #wrapper #footer {
    background-color: #000000;
    height: 20px;
    color: #CCCCCC;
    font-size: 13px;
    text-align: center;
    border-left-width: 3px;
    border-left-style: solid;
    border-left-color: #FFFFFF;
    }
    #wrapper #content {
    height: 800px;
    background-color: #000000;
    border-left-width: 3px;
    border-left-style: solid;
    border-left-color: #FFF;
    margin-top: 0px;
    }
    #wrapper #content #contentBox {
    height: 250px;
    width: 600px;
    margin-top: 20px;
    margin-right: auto;
    margin-bottom: 20px;
    margin-left: auto;
    }
    ------------------

    unfortunately i can't show a picture of what the page looks like, but any help would be much appreciated.

    Thanks,
    shake

  2. #2
    Join Date
    Feb 2006
    Location
    Salisbury UK
    Posts
    4,332
    for some reason the 'margin-top' property that i added to one element is moving the entire page contents down.

    That's what it's supposed to do. If you mean making margin-top: 20px; for #wrapper #content where you have margin-top: 0; at present, it will move the div down and show a white space above, moving everything else down too.

    One of the differences between margin and padding is that margin moves the whole div including its background-color but padding will move the div leaving its background-color in the padding, so try this instead:-

    #wrapper #content {
    height: 800px;
    background-color: #000000;
    border-left-width: 3px;
    border-left-style: solid;
    border-left-color: #FFF;
    /*margin-top: 0px;*/ padding-top: 20px;
    }

    You are using a doctype, aren't you?
    http://www.w3.org/QA/2002/04/valid-dtd-list.html

    like
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    Last edited by Wickham; 10 Jul 2009 at 02:12 AM.
    Code downloaded to my PC will be deleted in due course.
    WIN7; IE9, Firefox, Opera, Chrome and Safari for Windows; screen resolution usually 1366*768.
    Also IE6 on W98 with 800*600 and IE8 on Vista 1440*900.

Similar Threads

  1. REal Dumb problem with css please help
    By thrilldealer in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 15 Dec 2007, 08:34 PM

Posting Permissions

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