Forum Moderators: not2easy

Message Too Old, No Replies

strange IE6, IE7 and IE8 bugs !

padding and margin problems in IE

         

ahmedhelmy007

8:28 pm on Jul 10, 2009 (gmt 0)

10+ Year Member



i'm novice in CSS2.
when i begun designing my site i was testing it on firefox,
after finishing i was shocked...
the design looks different in each of IE6, IE7 and all the drama is in IE8 !
i think that the problem is that every version of IE treats padding and margins differently.

any help?

here is a piece of the design:


<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>ie6, ie7 problems</title>
<style type="text/css">
body {
background:#CCCCCC url(images/img01.jpg) repeat scroll left top;
color:#616161;
direction:rtl;
font-family:"Traditional Arabic",Times,serif;
font-size:16px;
margin-top:10px;
padding:0;
text-align:right;
}
#wrapper {
}
#page {
width: 90%;
margin: 0px auto;
background-repeat:repeat;
background-position:left bottom;
min-width:754px;
width: expression(document.body.clientWidth < 754? '754px');
}
#mainContent {
background: white url(images/white_pixel.jpg) repeat scroll left top;
margin:0px 0px -19px 184px;
padding:0px 0px 0px 0px;
}
#content {
border:0 solid red;
margin:8px 188px auto 9px;
text-align:justify;
}
#contentHeader {
height:1px; margin: 0 0 0 184px;
}
#contentHeaderLeft {
background: red url(images_temp/img04_1_1_1.gif) no-repeat scroll left top;
float:left;
height:30px;
width:12px;
}
#contentHeaderRight {
background: red url(images_temp/img04_1_3_1.gif) no-repeat scroll right top;
float:right;
height:30px;
width:12px;
}
#contentHeaderMid {
background: yellow url(images/img04_1_2_1.gif) repeat-x scroll 0 0;
height:30px;
margin:0 12px;
}
#contentFooter {
height:1px;
margin:auto;
padding:0;
}
#contentFooterLeft {
background:black url(images/img06_1_1.gif) no-repeat scroll left bottom;
float:left;
height:36px;
width:12px;
}
#contentFooterRight {
background:black url(images/img06_1_3.gif) no-repeat scroll right bottom;
float:right;
height:36px;
width:12px;
}
#contentFooterMid {
background:black url(images/img06_1_2.gif) repeat-x scroll 0 0;
height:36px;
margin:0 12px;
}
#indicator {
font-weight:bold;
padding:0 10px 0 0;
background-color:#00F30F;
}
.centered {
text-align:center;
}
.links {
font-weight:bold;
padding:4px 0;
text-align:right;
}
.links a {
border:medium none;
}
.links a:hover {
}
#sidebar1 {
float:right;
font-size:16px;
margin:auto -4px;
}
#sidebar2 {
float:left;
margin:0;
}
#sidebar2 li h2 {
padding:0 32px 10px 0;
}
#sidebar1 ul {
padding-bottom:20px;
}
#sidebar1 > ul > li {
margin-bottom:10px;
}
#sidebar1 li h2 {
color:#333333;
height:25px;
padding:8px 30px 0 0;
}
#sidebar1 li li a {
}
#rightMenu {
font-size:1.1em;
}
.sidebar {
float:left;
width:180px;
}
.sidebar ul {
list-style-image:none;
list-style-position:outside;
list-style-type:none;
margin:0;
padding:0;
}
.sidebar li {
padding:0 0 20px;
}
.sidebar li ul {
}
.sidebar li li {
border-bottom:1px dashed #B5B5B5;
font-weight:bold;
line-height:1.3em;
margin:0 10px;
padding:8px 0 8px 3px;
text-align:right;
}
.sidebar li h2 {
color:#FFFFFF;
font-size:20px;
height:30px;
margin:0;
}
.sidebar a {
margin:auto 14px;
}
</style>
</head>
<body>
<div id="wrapper">
<!-- start page -->
<div id="page">
<!-- start sidebars -->
<div id="sidebar2" class="sidebar" style="border: 1px solid blue;">
<ul>
<li>left menu <br>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
</li>
</ul>
</div>
<!-- end sidebars -->
<div id="contentHeader">
<div id="contentHeaderLeft"></div>
<div id="contentHeaderRight"></div>
<div id="contentHeaderMid"></div>
</div>
<div id="mainContent">
<!-- start content -->
<div id="content"> content line 1<br>
content line 2<br>
content line 3<br>
content line 4<br>
content line 5<br>
<br><br><br><br><br><br><br><br><br><br>
</div>
<!-- end content -->
<div id="contentFooter">
<div id="contentFooterLeft"></div>
<div id="contentFooterRight"></div>
<div id="contentFooterMid"></div>
</div>
</div>
<div style="clear: both;">&nbsp;</div>
</div>
</div>
</body>
</html>

[edited by: swa66 at 10:13 pm (utc) on July 10, 2009]
[edit reason] removed unintentional smiley [/edit]

marcel

8:07 am on Jul 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi ahmedhelmy007,

I haven't tested your code, but to avoid this problem I usually begin my CSS with a 'reset' (do a search for 'reset css' and you will find plenty of discussion on the subject)

Basically something like this:

html, body, div, span, object, iframe, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, em, img, q, dl, dt, dd, ol, fieldset, form, label, legend, table, caption
{
margin: 0;
padding: 0;
border: 0;
}

This will force all browsers to treat block level elements equally. Afterwards you should set the margin and padding as required on your elements.

ahmedhelmy007

9:22 pm on Jul 11, 2009 (gmt 0)

10+ Year Member



thanks marcel,
but, unfortunately , that didn't solve my problem.

ahmedhelmy007

9:05 am on Jul 13, 2009 (gmt 0)

10+ Year Member



any suggestions?

ahmedhelmy007

8:18 pm on Jul 14, 2009 (gmt 0)

10+ Year Member



hey! CSS Gurus! Where are you ?!

marcel

5:14 am on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It might be an idea to validate your code [validator.w3.org] first, as there are a number of errors.

Did the CSS reset make any difference at all?

ahmedhelmy007

8:42 am on Jul 31, 2009 (gmt 0)

10+ Year Member



thanks again marcel,
I've fix most validation issues but to no avail.
CSS reset just caused an increase in the design width but didn't fix anything .

ahmedhelmy007

9:20 am on Jul 31, 2009 (gmt 0)

10+ Year Member



ok, I've minimized the code as possible to facilitate helping me.

i only leaved the header.

open it in ie6 and note the space between the 3 DIVs.


<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<title>ie6, ie7 problems</title>
<style type="text/css">

/* CSS reset*/
html, body, div, span, object, iframe, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, em, img, q, dl, dt, dd, ol, fieldset, form, label, legend, table, caption
{
margin: 0;
padding: 0;
border: 0;
}

body {
background:#CCCCCC url(images/img01.jpg) repeat scroll left top;
color:#616161;
direction:rtl;
font-family:"Traditional Arabic",Times,serif;
font-size:16px;
margin-top:10px;
padding:0;
text-align:right;
}
#wrapper {
}
#page {
width: 90%;
margin: 0px auto;
background-repeat:repeat;
background-position:left bottom;
min-width:754px;
width: expression(document.body.clientWidth < 754? '754px');
}

#contentHeader {
height:1px; margin: 0 0 0 184px;
}
#contentHeaderLeft {
background: red url(images_temp/img04_1_1_1.gif) no-repeat scroll left top;
float:left;
height:30px;
width:12px;

}
#contentHeaderRight {
background: red url(images_temp/img04_1_3_1.gif) no-repeat scroll right top;
float:right;
height:30px;
width:12px;
}
#contentHeaderMid {
background: yellow url(images/img04_1_2_1.gif) repeat-x scroll 0 0;
height:30px;
margin:0 12px;
}

</style>
</head>
<body>
<div id="wrapper">
<!-- start page -->
<div id="page">

<div id="contentHeader">
<div id="contentHeaderLeft"></div>
<div id="contentHeaderRight"></div>
<div id="contentHeaderMid"><div style="width:1px;">title</div></div>
</div>
</div>
</div>
</body>
</html>

SuzyUK

10:58 am on Jul 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



#contentHeaderMid {
background: yellow;
height:30px;
margin:0 12px;
}

you shouldn't need that left and right margin, technically it's doing nothing, elements beside/between floats naturally sit right beside them.

BUT then because IE's quirky float model has been triggered (by the height on that div), you are seeing the wonderful IE 3px Float Bug (IE6 only) - you can fix it by feeding some negative margins on the left and right floats - to IE6 and below only. I've done it using a hack below, but you can put it inside a conditional comment if you prefer

#contentHeaderMid {
background: yellow;
height:30px;
/* margin:0 12px; this is not required */
}

* html #contentHeaderLeft {margin-right: -3px;}
* html #contentHeaderRight {margin-left: -3px;}

ahmedhelmy007

5:56 am on Aug 1, 2009 (gmt 0)

10+ Year Member



in fact i need that left and right margin, because the left and right DIVs contains rounded corners images with transparent background: img04_1_1_1.gif and img04_1_3_1.gif

-I set its background to red just for testing purpose-

ahmedhelmy007

6:00 am on Aug 7, 2009 (gmt 0)

10+ Year Member



can any one help me please?

Invent

8:20 pm on Aug 8, 2009 (gmt 0)

10+ Year Member



Hi Ahmed,

You're absolutely right: IE 6,7 and 8 all treat margins and padding differently.

IE 6 incorrectly calculates padding + width - instead of total width / height being CSS width: + padding: , it will instead simply be width: , with padding: subtracted from the inner area of the element

IE 6+7 Don't collapse top margins correctly. This is well documented

IE 8 does both of these things right, but then has some very odd margin collapse bugs.

I'd suggest getting your layout working in FF, and IE 8, then making any (should be minor tweaks) for IE 7.

For IE 6, you need to look up the html>body hack - this will be the best way to fix IE6's padding / width bugs

[edited by: swa66 at 12:48 am (utc) on Aug. 9, 2009]
[edit reason] No URLs, please see ToS and Forum Charter [/edit]

SuzyUK

4:59 pm on Aug 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



#contentHeaderMid {
background: yellow;
height:30px;
margin:0 12px;
}

* html #contentHeaderMid {margin: 0;}
* html #contentHeaderLeft {margin-right: -3px;}
* html #contentHeaderRight {margin-left: -3px;}

OK try this, the bottom three rules are for IE6 only, it doesn't need the margins, even with transparent images, it wrongly starts/ends the middle float where you want it anyway, then you still need the negative margins to counteract the secondary 3px bugs.