2

我正在尝试将 div 放置在页面的左上角,并且无论浏览器窗口大小调整或页面滚动如何,我都希望它留在那里。

如何使用纯 CSS(如果可能)或使用 jQuery 来做到这一点?

4

2 回答 2

6

使用 css 位置:固定;

#fixedDiv {
    position: fixed;
    left: 20px;
    top:20px;
    width: 50px;
    height: 50px;
}

对于 IE6,请参阅http://www.cssplay.co.uk/layouts/fixed.html

于 2009-06-18T16:01:40.913 回答
2
css-selector {
    position: fixed;
    top: 0;
    left: 0;
}

注意 z-index。更高 = 前景。

于 2009-06-18T16:02:58.370 回答