PDA

View Full Version : Position of block altered with IE7?



Whicksy
Apr 13th, 2009, 01:46 PM
Hello,

I have a block menu within container. The menu appears in the correct position in IE8,Chrome 1.0.154.53, Firefox 3.0.5. However in IE7 it is positioned higher(neared top of the border).

When I remove the width and height in the container the problem disappears?



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Block Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
#container {
text-align: left;
margin: 0 auto;
position: relative;
left:0px;
top:20px;
width:900px;
height:600px;
border-style: solid;
border-width: 1px;
}
#menuHome {
position:absolute;
left: 2px;
top: 2px;
}
#menuHome ul li {
display: block;
list-style: none;
font: 14px Verdana;
}
#menuHome a {
color: #999999;
text-decoration: none;
list-style: none;
}
#menuHome a:hover {
color: #000000;
}
</style>
</head>
<body>
<div id="container"; margin-top: 0;>
<div id="menuHome">
<ul>
<li><a href="#" title="home">Home</span></a></li>
<li><a href="#" title="services">Services</a></li>
<li><a href="#" title="projects">Projects</a></li>
<li><a href="#" title="testimonials">Testimonials</a></li>
<li><a href="#" title="contact">Contact</a></li>
</ul>
</div>
</div>
</body>
</html>



I am not very experienced using CSS, so any help would be much appreciated.

Thanks in advance

Whicksy
Apr 13th, 2009, 02:19 PM
Appologies, here is corrected code example>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Block Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
#container {
text-align: left;
margin: 0 auto;
position: relative;
left:0px;
top:20px;
width:900px;
height:600px;
border-style: solid;
border-width: 1px;
}
#menuHome {
position:absolute;
left: 2px;
top: 2px;
}
#menuHome ul li {
display: block;
list-style: none;
font: 14px Verdana;
}
#menuHome a {
color: #999999;
text-decoration: none;
list-style: none;
}
#menuHome a:hover {
color: #000000;
}
</style>
</head>
<body>
<div id="container">
<div id="menuHome">
<ul>
<li><a href="#" title="home">Home</a></li>
<li><a href="#" title="services">Services</a></li>
<li><a href="#" title="projects">Projects</a></li>
<li><a href="#" title="testimonials">Testimonials</a></li>
<li><a href="#" title="contact">Contact</a></li>
</ul>
</div>
</div>
</body>
</html>

BoldUlysses
Apr 13th, 2009, 05:04 PM
Give this a go:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Block Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">

* {
margin:0;
padding:0;
}

#container {
text-align: left;
margin:20px auto 0;
position: relative;
width:900px;
height:600px;
border-style: solid;
border-width: 1px;
}
#menuHome {
position:absolute;
left: 2px;
top: 2px;
}
#menuHome ul li {
display: block;
list-style: none;
font: 14px Verdana;
}
#menuHome a {
color: #999999;
text-decoration: none;
list-style: none;
}
#menuHome a:hover {
color: #000000;
}
</style>
</head>
<body>

<div id="container">
<div id="menuHome">
<ul>
<li><a href="#" title="home">Home</a></li>
<li><a href="#" title="services">Services</a></li>
<li><a href="#" title="projects">Projects</a></li>
<li><a href="#" title="testimonials">Testimonials</a></li>
<li><a href="#" title="contact">Contact</a></li>
</ul>
</div>
</div>

</body>
</html>

Your problem was coming from the fact that different browsers have different defaults when it comes to adding margins and padding. Adding the code above (called the "universal reset") effectively "zeroes out" the defaults and allows all browsers to start from the same place as far as margins and padding are concerned.

Also simplified a bit of your #container code.

Whicksy
Apr 14th, 2009, 12:24 AM
Thanks so much:), got back home this evening with perfect answer to my problem. Great. Will read up about "universal reset".