elmu
04-05-2008, 01:55 PM
Hello,
I have a small test code below. I want to display box and box2 div with a 20px margin. I want 20px from the top and 40px(2x20px) between the boxes.
My problems with my code:
1. In firefox I got 0px on the top, but there is a 20px space under the header div.
2. Both in IE and Firefox there is only 20px between the 2 boxes and not 2x20px.
3. In IE there is a small gap between the sidebar and content.
I think I don't know specialities about div tags margin handling.
How should I correct these errors?
Thanks in advance!
<!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>CSS Test</title>
<style type="text/css">
<!--
#header {
background-color: #999999;
margin: 0px;
padding: 0px;
height: 150px;
width: 800px;
}
#center {
background-color: #CCCCCC;
margin: 0px;
padding: 0px;
width: 800px;
}
#center #content {
background-color: #990000;
padding: 0px;
width: 600px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 190px;
border:0px;
}
#center #sidebar {
background-color: #0000CC;
margin: 0px;
padding: 0px;
float: left;
width: 190px;
border:0px;
}
#center #content #box {
background-color: #009900;
margin: 20px;
width: 500px;
}
#center #content #box2 {
background-color: #003300;
margin: 20px;
width: 500px;
}
-->
</style>
</head>
<body>
<div id="header"></div>
<div id="center">
<div id="sidebar">Menu-1<br/>Menu-1<br/>Menu-1<br/>Menu-1<br/></div>
<div id="content">
<div id="box">Box<br/>Box<br/></div>
<div id="box2">Box2<br/>Box2<br/></div>
</div>
</div>
</body>
</html>
I have a small test code below. I want to display box and box2 div with a 20px margin. I want 20px from the top and 40px(2x20px) between the boxes.
My problems with my code:
1. In firefox I got 0px on the top, but there is a 20px space under the header div.
2. Both in IE and Firefox there is only 20px between the 2 boxes and not 2x20px.
3. In IE there is a small gap between the sidebar and content.
I think I don't know specialities about div tags margin handling.
How should I correct these errors?
Thanks in advance!
<!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>CSS Test</title>
<style type="text/css">
<!--
#header {
background-color: #999999;
margin: 0px;
padding: 0px;
height: 150px;
width: 800px;
}
#center {
background-color: #CCCCCC;
margin: 0px;
padding: 0px;
width: 800px;
}
#center #content {
background-color: #990000;
padding: 0px;
width: 600px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 190px;
border:0px;
}
#center #sidebar {
background-color: #0000CC;
margin: 0px;
padding: 0px;
float: left;
width: 190px;
border:0px;
}
#center #content #box {
background-color: #009900;
margin: 20px;
width: 500px;
}
#center #content #box2 {
background-color: #003300;
margin: 20px;
width: 500px;
}
-->
</style>
</head>
<body>
<div id="header"></div>
<div id="center">
<div id="sidebar">Menu-1<br/>Menu-1<br/>Menu-1<br/>Menu-1<br/></div>
<div id="content">
<div id="box">Box<br/>Box<br/></div>
<div id="box2">Box2<br/>Box2<br/></div>
</div>
</div>
</body>
</html>