Forum Moderators: not2easy

Message Too Old, No Replies

Div Margin not Working in Firefox

         

wsamoht

2:59 pm on May 5, 2008 (gmt 0)

10+ Year Member



Here is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<link rel="stylesheet" href="styles.css" type="text/css" />
<style type="text/css">
.left_pic {
float: left;
}
.right_pic {
float: right;
}
.left_text {
float: left;
width: 350px;
border: 1px #000000 dashed;
padding: 10px;
margin-top: 35px;
}
.right_text {
float: right;
width: 350px;
border: 1px #000000 dashed;
padding: 10px;
margin-top: 35px;
}
.function {
width: 675px;
margin-left: auto;
margin-right: auto;
margin-top: 100px;
border: 1px #000000 dashed;
}

</style>
</head>

<body>

<tr>
<td class="page">
<img src="images/headers/functions_page.gif" alt="Functions" width="282px" height="98px" /><br />
[b]<div class="function">
<img class="left_pic" src="images/functions/wedding_anniversary.gif" alt="Weddings and Anniversaries" width="273px" height="141px" />
<div class="right_text">Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text </div>
</div>
<div class="function">
<img class="right_pic" src="images/functions/birthday.gif" />
<div class="left_text">Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text </div>
</div>
<div class="function">
<img class="left_pic" src="images/functions/wedding_anniversary.gif" alt="Weddings and Anniversaries" width="273px" height="141px" />
<div class="right_text">Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text </div>[/b]
</div>
</td>
</tr>

</body>
</html>


I am trying to get the bolded code above to display properly in firefox. It seems to work fine in IE. I am trying to get a top margin on the div's with class="function". I get it on the first one but not on any others in firefox. (I cut out the rest of the table tags to simplify the code, a little!) I know I could use a table instead of divs but I am trying to get away from using tables.

swa66

5:13 am on May 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was thinking to try to first validate the html. Invalid strict xhtml will significantly reduce your chances of it rendering as intended in a standards compliant browser.

Aside of that I think you fell in the trap of developing in IE: it's got a badly broken box model. Your div with a class of "function" contains nothing but floated elements and those are supposed to be taken out of the flow and that means your "function" divs have no height.

wsamoht

3:38 pm on May 6, 2008 (gmt 0)

10+ Year Member



The code does validate. I added height to my function class and it took care of the problem. Thank you so much!

swa66

12:53 am on May 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code does validate

Hmm, e.g.
<img class="right_pic" src="images/functions/birthday.gif" />

alt attribute is required on images ... The remaining <tr> and <td> that have no parent <table> are probably just a cut&paste error, but it makes the sample invalid as well, similarly a <head> needs a <title> in it. ...

Valid html is something that's not so easy to achieve, esp not against a strict DTD.

Regardless, glad you found a solution.

swa66

3:06 am on May 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps I should add that setting height is one solution, but that I'd typically verge to using an element in the flow (hence not floated itself) that's got a clear on it.

wsamoht

6:22 pm on May 7, 2008 (gmt 0)

10+ Year Member



I am just starting to use css and divs to structure my pages turning away from tables. What do you mean by you'd
typically verge to using an element in the flow (hence not floated itself) that's got a clear on it.
Can you give me an example of how this should be done?

swa66

5:15 am on May 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well you seem to know how to float, so here's how to clear:

Something like:

<div class="tobestretched">
<img class="tobefloated" ... />
...
<img class="tobefloated" ... />
<br class="clear" />
</div>

And in CSS:

img.tobefloated {
width:10px;
height:10px;
float:left;
...
}
.clear {
clear:both;
}

You can use other elements than a <br> to add the clear on, that's up to you and what makes semantical sense in the html.