Hi guys,

In order to test the css position property, I wrote the following page to test this property. But this page display different in ie6 and firefox. The ie6 version is wrong. How can I change the code to fix it? Thanks.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Page Title</title>
<style type="text/css">
#outer{
    margin:50px;
    position:relative;
    height:20px;
}
#outer input{
    border:1px solid #999;
}
#outer #pop{
    border:1px dashed #666;
    position: absolute;
    top:20px;
    left:0px;
    background-color:#add;
}

</style>
</head>
<body>
<div id="outer">
    <input type="text" /> <input id="toggle" type="button" value="toggle" />
    <div id="pop" style="display:none">
        <ul>
            <li>aaaaaa</li>
            <li>bbbbbb</li>
            <li>cccccccc</li>
            <li>dddddddd</li>
            <li>eeeeeeee</li>
            <li>ffffffff</li>
        </ul>
    </div>
</div>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p>Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<script type="text/javascript" charset="utf-8">
    function showhidepop(){
        var display = document.getElementById("pop").style.display;
        if(display == "block"){
            document.getElementById("pop").style.display = "none";
        }else{
            document.getElementById("pop").style.display = "block";
        }
    }

    var t = document.getElementById("toggle");
    if(document.addEventListener){
        t.addEventListener("click", function(e){
            showhidepop();
        }, false);  
    }else if(document.attachEvent){
        t.attachEvent("onclick", function(e){
            showhidepop();
        });
    }
</script>
</body>
</html>

1 answer

danwellman 5600
3
points
This was chosen as the best answer

IE6 certainly is wrong ;)

The margin on the #outer element is contributing to the mis-alignment in IE6 - remove this margin and the popup lines up perfectly in both IE6 and FF, however, it is actually the input element that is in the wrong place, the popup is displaying in the correct place.

Sometimes there is no single golden rule that fixes layout issues such as this in all browsers, and you may need to resort to targetting IE6 specifically. A conditional comment containing a style that fixes the input position, can be used like this:

<!--[if IE 6]>
<style>
    input { position:relative; left:-50px; }
</style>
<![endif]-->

Put this directly after your existing style rule and everything is positioned correctly...

Answered over 6 years ago by danwellman
  • Thank you danwellman for your help! Yousui over 6 years ago
  • no problem :) danwellman over 6 years ago