CSS: margin attributes not working in Firefox - Geeks to Go Forums

Jump to content

Log in Register Register Malware removal guide How it works

CSS: margin attributes not working in Firefox A wrapping DIV contains four children; IE properly rendering CSS, Fire

#1 KingTheoden

  • Group: Member
  • Posts: 21
  • Joined: 27-December 07

Posted 16 February 2008 - 02:19 PM

This is one of the more interesting problems that I have encountered in developing my website. IE is working, but Firefox is failing!

Essentially, the problem is that I have a containing div, contentMain, that is parent to one div, contentBar, which has two horizontally stacked child div elements, infoBoxL and infoBoxR and another (which is alone). Now, I am floating left infoBoxL and infoBoxR and the rendering is fine. In infoBoxMid, I clear the float but want there to be some whitespace between the two former content containers.

Attempting a margin-top, Firefox does nothing while IE properly displays the content with the margin space. My eyes are glazed so I cannot be sure of the source, but I am hypothesizing that it has something to do with an inline attribute.

Any help would be extremely appreciated, particularly because I want to get to my javascript and am furious at myself for being bogged down in CSS. Anyway...

Since psionics are for games, here is my css and html code:

/* CSS Document */
* {
padding:0;
margin:0;
}
/*
#content {
position:relative;
left:0;
width:970px;
border:1px solid #000066;
background-color:#FFFFFF;
color:#666666;
display:block;
margin: 0 0 0 0;
padding: 0 0 0 0;
min-height: 500px;
}
*/

#contentMain {
position:relative;
margin: 20px 10px 20px 15px;
width:678px;
overflow:auto;
border:solid 1px #000066;
}

.contentBar{
position:relative;
margin-top:30px;
margin-bottom:35px;
margin-left:auto;
margin-right:auto;
width:650px;
color:#666666;
}

#infoBoxL {
width:300px;
margin-top:5px;
margin-bottom:5px;
float:left;
}

#infoBoxR{
width:300px;
margin-top:5px;
margin-bottom:5px;
margin-left: 35px;
float:left;
}

#infoBoxMid {
position:relative;
background-color:#666666;
margin-left:auto;
margin-right:auto;
width:320px;
clear:left;

}
/*
#contentSide {
width:200px;
margin-top:20px;
margin-left:10px;
float:left;
}

.sidePill {
margin-left:auto;
margin-right:auto;
width:170px;
}
*/

.pHeading{
font-family:Georgia, Times New Roman, Times, serif;
text-align:left;
font-size:medium;
font-weight:bold;
color:#000066;
}


<!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=iso-8859-1" />
<title>Mangin Web Development</title>

<link href="assets/styles/styles_content.css" rel="stylesheet" type="text/css" />

</head>

<body>
<div id="contentMain">
<div class="contentBar">

<div id="infoBoxL">
<p class="pHeading">Web Development</p>
<p>Our company specializes in planning, configuring, developing, and deploying websites for a range of needs. Perhaps you are a client in need of revamping a current site, or you are new to the Internet. Whatever the case, our company promises to meet your needs with personalized and dedicated service and support.</p>
</div>

<div id="infoBoxR">
<p class="pHeading">Consulting and Instruction</p>

<p>Businesses must remain well-versed in the latest information technologies in order to maintain and improve the effectiveness of their web platforms. Our company offers consulting services to ensure that systems administrators keep their firms as internet leaders.</p>
</div>
</div>


<div id="infoBoxMid">
<p class="pHeading">Why Us?</p>
<p>
&raquo; Data Security and Integrity<br />
&raquo; Transparent Pricing and Project Management<br />
&raquo; Personalized Service<br />
</p>
</div>
</div>
</div>

<div id="contentSide">
<div class="sidePill">
<p> This is side pill element A. This is just filler text.</p>
</div>
<div class="sidePill">
<p> This is side pill element B. This is just filler text. There is a serious problem with the layout of this CSS and I am determined to resolve it in time for tomorrow evening.</p>
</div>
</div>



</body>
</html>

#2 Major Payne

  • Group: Retired Staff
  • Posts: 5,307
  • Joined: 26-January 05

Posted 16 February 2008 - 03:17 PM

My eyes aren't glazed yet, but the only difference I see between FF 2.0.0.12 and IE is the usual IE problem of getting sizes correct. Other then that they look identical so I must not be seeing what you're seeing.

Ron

#3 KingTheoden

  • Group: Member
  • Posts: 21
  • Joined: 27-December 07

Posted 16 February 2008 - 03:42 PM

Thank you very much Major Payne for the quick reply!

I hope that I am chasing a phantom, but the problem as I see it is specific to the vertical space between the two horizontal infoBox elements and the infoBoxMid element (i.e., the one that reads 'Why Us...')

If I take away the margin-bottom attribute from contentBar element, in IE the lower element jumps up 35px while nothing happens in Firefox 2.0.0.1.2. Similarly, if I add margin-top y px to infoBoxMid, IE shows the added whitespace while nothing happens in Firefox.

I'm back to tinkering with it so perhaps I will figure out what the issue is. Thanks again for your assistance!

#4 Major Payne

  • Group: Retired Staff
  • Posts: 5,307
  • Joined: 26-January 05

Posted 16 February 2008 - 04:00 PM

It may be related to IE's Box Model problem. IE does not calculate the way it is suppose to as it is a non-compliant browser. Firefox meets pretty near all the CSS2 standards. If it looks the way it should be in FF, then your coding is correct. Then you have to use a separate IE only CSS or conditional statements to get IE to behave.

In FF, the "Personalize Services" and its container are about half way down using 1024x768 res and a 17-inch flat screen. With IE, the same is over half way down. You can see a gig jump when switching between FF and IE.

IE does not recognize min-height. I haven't discovered any more problems with IE yet, but these two should give you a good idea of what to look for.

Known Bugs

Ron

#5 KingTheoden

  • Group: Member
  • Posts: 21
  • Joined: 27-December 07

Posted 16 February 2008 - 06:42 PM

Topic solved! It was entirely simple. How it eluded me, I will never know.

The problem was with the wrapper class element, contentBar. I needed to add the following style attribute: overflow:auto. That I did not do this before caused the wrapper to collapse since the child elements are floated.

Margins are working fine in IE and Firefox. Thanks for your input!

#6 Major Payne

  • Group: Retired Staff
  • Posts: 5,307
  • Joined: 26-January 05

Posted 16 February 2008 - 06:57 PM

Glad you got it solved. Got side-tracked and didn't get back to your code.

Ron

#7 coljung

  • Group: Member
  • Posts: 47
  • Joined: 05-July 05

Posted 23 February 2008 - 03:01 PM

Yeah, usually when u're getting problems with FF and not IE, it means that you're doing something wrong with your CSS.

#8 wardct

  • Group: Member
  • Posts: 1
  • Joined: 01-June 08

Posted 01 June 2008 - 05:59 AM

View PostKingTheoden, on Feb 17 2008, 01:42 AM, said:

Topic solved! It was entirely simple. How it eluded me, I will never know.

The problem was with the wrapper class element, contentBar. I needed to add the following style attribute: overflow:auto. That I did not do this before caused the wrapper to collapse since the child elements are floated.

Margins are working fine in IE and Firefox. Thanks for your input!


I encountered a similar problem, and the overflow:auto solution has worked for me too - happy days! :)
What I don't understand is how this works. If the overflow property sets what happens if the contents of an element overflows its area, I don't see the relationship with margin-top here? Can someone please enlighten me.

#9 Maitreya

  • Group: Member
  • Posts: 3
  • Joined: 08-June 10

Posted 08 June 2010 - 02:02 AM

Kudos to you KingTheoden...this problem was driving me nuts... Thanks a ton!

#10 calvers7

  • Group: Member
  • Posts: 1
  • Joined: 04-July 12

Posted 04 July 2012 - 05:22 PM

I'd just like to say thanks for posting how you solved this. I've been having a nightmare with exactly the same thing and it's very late so didn't fancy spending ages trying to solve what I was sure would be quite simple. Couldn't believe IE was doing it better than FF either :)

Share this topic: