日期:2014-05-16  浏览次数:20328 次

让人蛋疼的百分比相对定位问题,求高人解答
HTML code
<!doctype html>
<html>
    <head>
        <style type="text/css">
            #test{
                border:1px solid black;
            }
            #sub{
                position: relative;
                width: 200px;
                top: 50%;
                left: 50%;
            }    
        </style>
    </head>
    <body>
        <div id="test">
            <div id="sub">asljkkdfjkasdf</div>
        </div>
    </body>        
</html>
这个简单的页面在firefox,chrome下并没有出现预想的效果,而在一向被我摒弃的IE上面,居然。。好吧,这个是的对相对定位的理解错误呢还是firefox, chrome的bug?

------解决方案--------------------
测试了下,position为relative时,top如果为百分比的话,确实在不同浏览效果会有所不同,
建议在position为relative时,top不用百分比,而用数值