FF and IE margin-top issue

I’m working on a website and am having an issue with the top margin on a <div> tag. It looks fine in FF, but in IE the tag the image starts lower than it should. The site is online at www.mverminski.com/test and my CSS is below. I’ve researched the issue already and have tried different hacks and approaches to fixing it, but haven’t been successful. Here is my CSS:

*{margin:0; padding:0;}

html, body {
	height: 100%;
}

body {
	background-image: url(../images/IMG_BGPattern.png);
	background-repeat: repeat;
}

#container {
	width: 800px;
	margin-left: auto;
	margin-right: auto;
	background-color: #feeb45;
	min-height: 100%;
	margin-bottom: -83px;
	border-left: #000000 solid thin;
	border-right: #000000 solid thin;
}

#header {
	background-image: url(../images/IMG_Header.png);
	width: 800px;
	height: 140px;
}

.head {
	margin: 38px 0px 0px 22px;
	border: none;
}

#nav {
	width: 142px;
	padding-top: 12px;
}

.navimg {
	padding-bottom: 5px;
}

#info {
	width: 200px;
	margin: 10px 0px 0px 10px;
	position: inherit;
}

#arrow {
	float: left;
	width: 105px;
	margin: -153px 0px 0px 142px;
	padding: 0px;
	display: inline;
}

#bodywrap {
	float: right;
	width: 470px;
	margin: -163px 82px 0px 0px;
}

#color {
	background-repeat: no-repeat;
	width: 470px;
	margin-top: 20px;
}

.red {
	background-image: url(../images/IMG_RedTop.png);
	background-color: #e20a0a;
}



#content {
	width: 431px;
	margin-top: 0px;
	padding: 130px 20px 20px 20px;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #FFFFFF;
}

.clearfooter {
	height: 83px;
	clear: both;
}

#footer {
	background-image: url(../images/IMG_Footer.png);
	background-repeat: no-repeat;
	margin: 0px auto;
	width: 800px;
	height: 83px;
	position: relatve;
}

#footcontent {
	width: 800px;
	margin-top: 60px;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #000000;
}

.footerpos {
	padding-top: 5px;
}

Hi MVerminski, Welcome to SitePoint! :slight_smile:

You will be better off floating everything to the left that is under your header. That is the #nav, #arrow, and #bodywrap divs. That will allow you to get rid of all those huge negative top margins you are using. Then set that arrow image as a BG image on the arrow div.

That will get you looking the same in FF and IE (6-8). You also need to reset the vertical-align to bottom on those nav images.

This should get you sorted out for now. You can remove everything in red, I just left it there to show what I changed.


#nav {
    width: 142px;
    padding-top: 12px;
    [COLOR=Blue]float:left;[/COLOR]
}
[B]#nav img [/B][COLOR=Blue]{vertical-align:bottom}[/COLOR]

.navimg {
    padding-bottom: 5px;
}

#arrow {
    float: left;
    [COLOR=Blue]width: 106px;
    height: 135px;[/COLOR]
    [COLOR=Red]/*margin: -153px 0px 0px 142px;*/[/COLOR]
    [COLOR=Blue]margin: 23px 0 0;[/COLOR]
    [COLOR=Blue]background:lime url(../images/IMG_ArrowRed.png) no-repeat;[/COLOR]
    [COLOR=Red]/*padding: 0px;*/
    /*display: inline;*/[/COLOR]
}

#bodywrap {
    [COLOR=Blue]float: left;[/COLOR] [COLOR=Red]/*right*/[/COLOR]
    width: 470px;
    [COLOR=Red]/*margin: -163px 82px 0px 0px;*/[/COLOR]
    [COLOR=Blue]margin: 13px 0 0;[/COLOR]
    border: none;
}

Then just leave the arrow div empty in the html since it is now a BG image

<div id="arrow"></div>

Thanks for your reply. I added your changes and everything is working in IE and FF. Thanks a lot! If I want to add a block of text under the nav should I float that to left as well. I tried to do this and it placed it below everything. Is using negative numbers for the top margin acceptable or is there a better way to place this div?

Disregard my last post. I got the div to show correctly in FF, but in IE it doesn’t show up at all.

This is what I have for the CSS code:

#info {
	float: left;
	width: 200px;
	margin: 190px 0 0 10px;
	position: absolute;
}

I placed the info div right above the clearfooter div in my HTML

If I want to add a block of text under the nav should I float that to left as well. I tried to do this and it placed it below everything.

It went below all the other floats because there was no room for it, that’s called float drop. If you want another block under the nav it would be best to rework the links in that nav div. They really need to be set up as list items in a UL. Then you could just call that nav div your left column and you would hook that nav id to the UL. Basically your just turning that div into your left column and the info div would be nested in there after the UL.

I got the div to show correctly in FF, but in IE it doesn’t show up at all.

You don’t want to use absolute position along with a float, it nullifies the float and AP elements are removed from the flow.

If my explanation above about nesting your nav and info in a left column was confusing just let me know and I will work up an example.

Hi,
Your page has a lot of deprecated markup which is the reason your using a transitional doctype. These days when your building new pages it is strongly encouraged to break away from those and use strict doctypes. That will help you learn to write valid up to date code.

I went ahead and set up your left column with that info div and cleaned your page up. I set up your left nav and footer links as list items in a UL, that way you are able to style them with margins/paddings instead of using spacer divs like you were doing.

These should work out much better for you:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Pic-n-Color - Convert your photographs into coloring pages!</title>
    <link href="styles/main.css" rel="stylesheet" type="text/css" media="all">
</head>

<body>
<div id="container">
    <div id="header">
        <a href="index.html"></a>
    </div>

    <div id="left">
        <ul id="nav">
            <li>
                <a href="index.html">
                    <img src="images/BTN_HomeX.png" title="Pic-n-Color Home" alt="Convert your photographs to coloring pages with Pic-n-Color">
                </a>
            </li>
            <li>
                <a href="about.html">
                    <img src="images/BTN_About.png" title="About Pic-n-Color" alt="Learn about converting photographs into coloring pages with Pic-n-Color">
                </a>
            </li>
            <li>
                <a href="gallery.html">
                    <img src="images/BTN_Gallery.png" title="Pic-n-Color Gallery" alt="Examples of photographs converted to coloring pages using Pic-n-Color">
                </a>
            </li>
            <li>
                <a href="contact.html">
                    <img src="images/BTN_Contact.png" title="Contact Pic-n-Color" alt="Contact Pic-n-Color to learn more about making coloring pages out of photographs">
                </a>
            </li>
        </ul>
        <div id="info">
            <p>Info div here</p>
            <p>Info div here</p>
            <p>Info div here</p>
            <p>Info div here</p>
        </div>
    </div>

    <div id="arrow"></div>

    <div id="main">
        <div id="content">
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elit urna, aliquam sit amet volutpat eu, consectetur 
            non purus. In ut dui quam. Donec velit dolor, fermentum eu tincidunt tincidunt, commodo quis massa. Praesent 
            vulputate massa ac urna lobortis a feugiat libero hendrerit. Pellentesque a tortor sem, elementum ultrices sapien. 
            Aenean mi odio, blandit vitae eleifend sed, ultricies nec sapien. Proin eu nisi quam. Quisque bibendum ante 
            sollicitudin mi consequat auctor. Vestibulum elementum suscipit magna, id egestas felis dapibus in. Curabitur s
            celerisque congue dapibus. Aliquam ut nibh velit, quis lacinia tellus.</p>
    
            <p>Donec luctus elementum nibh, tempor pretium ipsum vehicula id. Donec sapien eros, aliquam eget congue eu,
            dapibus at sapien. Proin tincidunt, leo nec sagittis elementum, neque augue commodo ipsum, quis facilisis augue 
            sem vitae nulla. Curabitur eget metus nulla, at porttitor sem. Etiam posuere, lectus in iaculis ultricies, turpis justo 
            tristique tellus, sed tempus leo justo pharetra enim. Fusce vitae tortor sem, non ornare diam. Aenean dignissim 
            eros eu turpis semper nec faucibus metus sodales. Sed sapien sem, iaculis sed viverra at, egestas sit amet leo. 
            Proin at orci eget risus facilisis tristique vitae eget risus. Vestibulum a velit tortor, sit amet interdum tortor.</p>
        </div>
    </div>
</div>

<div id="footer">
    <ul id="footnav">
        <li><a href="index.html">Home</a>|</li> 
        <li><a href="about.html">About</a>|</li>
        <li><a href="gallery.html">Gallery</a>|</li>
        <li><a href="purchase.html">Purchase</a>|</li>
        <li><a href="contact.html">Contact</a>|</li>
        <li>&nbsp;Web Design by &nbsp;<a href="http://www.mverminski.com">Mike Verminski</a></li>
    </ul>
</div>

</body>
</html>

And here is the CSS that goes with that revised html

html, body {
    height: 100%;
}
body {
    margin: 0;
    padding: 0;
    background: url(../images/IMG_BGPattern.png);
}
ul, ol {
    margin: 0;
    padding: 0;
    list-style: none;
}
img, fieldset {
    border: none;
}
#container {
    width: 800px;
    min-height: 100%;
    margin: -83px auto 0;
    background-color: #feeb45;
    border: solid #000;
    border-width: 0 1px;
    overflow: hidden;
}
* html #container {height:100%;} /*min-height for IE6*/

#header {
    width: 800px;
    height: 140px;
    border-top: 83px solid red;/*reclaim negative top margin on container*/
    background-image: url(../images/IMG_Header.png);
}
#header a {
    display: block;
    width: 451px;
    height: 80px;
    margin: 38px 0px 0px 22px;
}
#left {
    width: 142px;
    padding-top: 12px;
    float: left;
}
ul#nav {
    width: 100%;
    overflow: hidden;
}
#nav li {
    display: block;
    padding: 0 0 5px 0;
}
#nav a {
    display: block;
    text-decoration: none;
}
#nav img {
    vertical-align: bottom;
}
#info {
    width: 100%;
    padding: 1px 0;
    background: orange;
}
#info p {
    margin: 10px;
    font: 12px/1.3 Arial, Helvetica, sans-serif;
}
#arrow {
    float: left;
    width: 106px;
    height: 135px;
    margin: 23px 0 0;
    background: lime url(../images/IMG_ArrowRed.png) no-repeat;
}
#main {
    float: left;
    width: 470px;
    margin: 33px 0 20px;
    background: #e20a0a url(../images/IMG_RedTop.png) no-repeat;
}
#content {
    width: 430px;
    padding: 130px 20px 29px 20px;
    font: 12px/1.3 Arial, Helvetica, sans-serif;
    color: #FFF;
    background: url(../images/IMG_RedBottom.png) no-repeat 0 100%;
}
#footer {
    width: 800px;
    height: 83px;
    margin: 0 auto;
    overflow: hidden;
    background: url(../images/IMG_Footer.png) no-repeat;
    border: solid #000;
    border-width: 0 1px;
}
ul#footnav {
    margin-top: 55px;
    font: 12px/1.3 Arial, Helvetica, sans-serif;
    color: #000;
    text-align: center;
}
#footnav li {
    display: inline;
    margin: 0 2px 0 0;
}
#footnav a {
    margin: 0 5px 0 0;
}

Wow thanks a lot. I’m just finishing schooling for web design. I thought I was doing well. I guess I still have a lot to learn lol I do have one question though. How come when using the code you provided the page looks like a mess in Dreamweaver, but displays perfectly in the browsers?

How come when using the code you provided the page looks like a mess in Dreamweaver, but displays perfectly in the browsers?
Because DW is not a browser and I assume it’s preview is really only close when it spits out it’s own code. This is a good example of why you should never depend on DW to write code for you. I don’t use DW but I think it’s called “Design View”, most people around here that use DW turn it off and use “Code View”.

You could also set your crayon images as BG images on the LI anchors. I removed that html image you had in the header and set up an anchor in it’s place that positioned in the same place on the BG image.

There is one other thing that needs to be added to the CSS and that is the min-height:100% bug fixes for Opera and IE8. I was waiting to see if you would come back before I mentioned it.

Slip these :before and :after pseudo elements in before your #container rules in the CSS and then remove overflow:hidden from #container as Opera will choke on it when using the pseudo blocks.

There is other things that could be done such as replacement text in the header but this should get your sticky footer straightened out for now. :wink:


img, fieldset {
    border: none;
}

/*=== Float Containment and Bug Fixes (Do Not Alter These!) ===*/
[COLOR=Blue]body:before [/COLOR]{/*Opera min-height 100% Fix*/
    content:"";
    height:100%;
    float:left;
    width:0;
    margin-top:-32767px;/*eliminate need for inner non clearing element*/
}
[COLOR=Blue]#wrapper:after,[/COLOR]  /* #wrapper:after for IE8 min-height:100% Fix*/
[COLOR=Blue]#container:after [/COLOR]{ /* #container:after for Float Containment */
    clear:both;
    content:"";
    display:block;
    height:1%;/*fix IE8 min-height:100% bug*/
    font-size:0;
}

#container{
    width: 800px;
    min-height: 100%;
    margin: -83px auto 0;
    background-color: #feeb45;
    border: solid #000;
    border-width: 0 1px;
    [COLOR=Red]/*overflow: hidden; remove this when using :before/:after blocks above*/[/COLOR]
}
* html #container {height:100%;} /*min-height for IE6*/

I use split view in DW and preview the site in browsers constantly it usually does a pretty good job at displaying everything correctly. I have only been doing web design stuff for about two years, but mostly just school projects and I really appreciate your help. This is the first site I am building for an actual client.

How long have you been doing this stuff? You really know A LOT about it.