Skip navigation
Wauga
Currently Being Moderated

The top margin for a header in this div is ignored when viewed in browsers

Jun 13, 2012 12:18 PM

I have 3 divs total in the document. One the serves as the header (div#navigation_bar)  which is in the body with a width of 100%, one inside div#navigation_bar (div#navigation_bar_content) which has a width of 920 px and is the same height as the div#navigation_bar, and one in the body with a width of 920 px and 750 px as the height (div#content). I gave div#navigation_bar the float left property and then gave div#content the clear left property and gave it a top margin of zero and left and right margin of auto, so the overall result is that the div#content appears right below the div#navigation_bar and is centered. So I inserted a header 1 in the div#content with the text "Welcome" then formatted that with an h1 tag style. I set all the margins the same for it and it worked in design view after I applied it. But when I tested it in every browser the top margin for "Welcome" was ignored and was like 5 px from the top border of div#content. It only ignores the top margin for some reason. This is my first site so bear with me

 

Edit: I use dreamweaver CS5.5

 
Replies
  • Currently Being Moderated
    Jun 13, 2012 12:37 PM   in reply to Wauga

    Answers to layout questions are contained in your HTML and CSS code.  For quick answers, upload your page to your remote site and post a URL for us to see in our browsers.

     

    A less preferred 2nd option is to copy & paste your code (all of it) into a web forum reply (don't use email for this as code won't come through.)

     

     

     

     

     

    Nancy O.

    Alt-Web Design & Publishing

    Web | Graphics | Print | Media  Specialists 

    http://alt-web.com/

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 16, 2012 11:33 AM   in reply to Wauga

    I can't tell much from the code you posted.

     

    Copy & Paste this into a new, blank document.  Adjust CSS colors & backgrounds to suit.  Note: I used embedded CSS here for expediency.  You can move CSS styles to your external file.

     

    <!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>Cento Media Home</title>
    
    <style type="text/css">
    
    body {
    font-family:Georgia,"Times New Roman", Times, serif;
    font-size: 16px;
    background-color: #000;
    background-image: url(space2.jpg);
    color: #FFF;
    width: 920px;
    margin:0 auto;
    border: 4px solid silver;
    }
    
    #header {
    background-color: #666;
    overflow:hidden; /**to control floats**/
    }
    
    #header a img {
    float:left; 
    padding: 20px;
    border:none;
    }
    
    /**top menu**/
    #nav ul {
    padding:0;
    margin:0;
    }
    
    #nav li {
    list-style:none;
    margin:0;
    padding:0;
    font-size: 25px;
    text-align:center;
    }
    
    #nav li a {
    float:left;
    display:block;
    width: 8em;
    color: red;
    text-decoration:none;
    background-color: #CCC;
    border: 1px solid #FFF;
    }
    #nav li a:visited {color: #333}
    
    #nav li a:hover,
    #nav li a:active,
    #nav li a:focus {
    color: #FFF; 
    background: red;}
    /**end top menu**/
    
    #content {
    background-image: url(content.png);
    margin:0;
    padding:30px 12px 0 12px;
    }
    
    #footer {
    margin:0;
    padding:0;
    border-top: 3px solid #CCC;
    background-color: #FFF;
    color: #000;
    text-align:center;
    font-size: 12px;
    }
    
    /**TEXT STYLES**/
    p {font-size: 16px;}
    h1 {font-size: 50px;}
    h2 {font-size: 25px;}
    h3 {font-size: 18px}
    
    </style>
    </head>
    
    <body>
    <div id="header"> 
    <a href="#"><img src="logo.png" alt="logo" width="116" height="85"/></a>
    <h1>Welcome to Cento Media</h1>
    
    <ul id="nav">
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Contact</a></li>
    <!--end nav--></ul>
    
    <!--end header--></div>
    
    <div id="content">
    <h2>Heading 2</h2>
    <p>Description goes here...</p>
    
    <h3>Heading 3</h3>
    <p>Description goes here...</p>
    
    <h4>Unordered List:</h4>
    <ul>
    <li>some list item</li>
    <li>some list item</li>
    <li>some list item</li>
    <li>some list item</li>
    </ul>
    
    <h4>Ordered List:</h4>
    <ol>
    <li>some list item</li>
    <li>some list item</li>
    <li>some list item</li>
    <li>some list item</li>
    </ol>
    <!--end content --></div>
    
    <div id="footer">
    &copy; 2012 your footer message goes here...
    </div>
    
    </body>
    </html>

     

     

    Nancy O.

    Alt-Web Design & Publishing

    Web | Graphics | Print | Media  Specialists 

    http://alt-web.com/

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points