Forum Moderators: not2easy

Message Too Old, No Replies

Firefox renders CSS each time differently

Firefox renders FLOATING ELEMENTS each time differently

         

iFloat

5:51 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Hi!

I've got two divs in one container div. Both divs are positioned to float left (so it looks like two table cells in a row, one for menu on the left and one for content on the right).

Everything looks nice in IE, Opera and (most of the time) in Firefox.

The problem is Firefox -> if I refresh the page 10 times, 6 times out of 10 the floating will be broken - the second div will appear UNDER the first div, not on the RIGHT.

I don't really know what to do since the problem appears so random (:

Any ideas?

I am using HTML 4.01 Strict doctype with IE 6, Opera 8 and Firefox 1.0.2.

Ps. Would an XHTML 1.0 Strict doctype be more appropriate?

Longhaired Genius

6:30 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Try giving both divs a specific width (say, in percentages) such that they will definitely fit across the page.

Of course, this means you might run into IE box-model problems. But that's another story.

iFloat

6:33 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Yeah, I forgot to mention, the widths are:
container: 780px;
first div: 140px;
2nd div: 630px + 10px padding left;

The important (and confusing, to me) part is, that it works (and breakes) randomly (:

drhowarddrfine

6:38 pm on Jun 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have a border around anything? This could offset things by 1px and overflowing but I don't know why it would be intermittent.

Longhaired Genius

6:53 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Yep, just too tight. Reduce the size of one of the divs by a couple of pixels and you should be ok.

iFloat

11:29 am on Jun 10, 2005 (gmt 0)

10+ Year Member



Thanks for the advice - I tried loosening it for a couple of px but the problem persists.

It seems that only the float: left; rule in CSS is being ignored randomly - everything else always renders correctly.

Longhaired Genius

11:37 am on Jun 10, 2005 (gmt 0)

10+ Year Member



I'm sure no part of the css is being ignored. Post the relevant part of your code. What you want to do has been done a million times so I'm sure the problem is fixable.

Longhaired Genius

11:42 am on Jun 10, 2005 (gmt 0)

10+ Year Member



Also, here's a floated layout with percent-based widths that might be of some use to you: [webmasterworld.com...]

iFloat

7:25 am on Jul 14, 2005 (gmt 0)

10+ Year Member



I had a friend take a look at my layout and the problem was solved instantly (:

I'll post it, maybe it'll help someone.

So, this is the working layout (only the very basic elements for the sake of simplicity)

CSS:

#contain {
width: 772px;
text-align: left;
margin-left: auto;
margin-right: auto;
border: 1px solid black;
background: white url(site_img/menubg.gif) repeat-y top left;
}
#menu {
width: 140px;
float: left;
background-color: #A1A8B0;
text-align: left;
padding-top: 10px;
}
#content {
width: 624px;
float: right;
vertical-align: top;
background-color: white;
}
#footer {
background-color: #EAEBED;
text-align: center;
padding: 5px 0px 3px 0px;
font-size: 11px;
width: 100%;
clear: both;
}

XHTML

<!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>
<title>Title</title>
<link rel="stylesheet" href="index.css" type="text/css" title="default" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />
</head>
<body>
<div id="contain">
<div id="menu">Here goes the menu thingy</div>
<div id="content">Here there be content</div>
</div>
<div id="footer">copyright 'n stuff</div>
</body>
</html>

The reason for randomly 'ignoring' the float: left; property of the #menu and #content divs was that #container had the display: table; property set. I had to remove this property and set the footer to clear: both; so it doesn't jump up to the header. There - the layout is now rock solid - with one flaw.

Since I removed the display: table; property from the #container, it's height is now 0px because both elements inside are floating. I have yet to overcome this issue, any pointers? (:

createErrorMsg

11:08 am on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it's height is now 0px because both elements inside are floating

Several choices:

(a) float the container. This forces it to expand and contain it's floated children.

(b) add a clearing element (a <br /> set to clear:both, for instance) to the bottom of the container.

There are a few other ways to do this, but these two are the clearest, simplest, and quickest.

cEM

iFloat

6:54 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



I tried both:

a) I set the #contain to float: center;, still height 0px;

b) Just before the finishing div I added this: <br style="clear: both;" /> ... no change.

iFloat

9:13 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



I'm such a silly sod, I put the cleared element in the content div, not the container div.

It works excellent in the container div, thanks!

createErrorMsg

9:29 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



float: center;

The possible values for float [w3.org] include left, right and none.