簡體   English   中英

如何使DIV始終浮在右上角的屏幕上?

[英]How to make a DIV always float on the screen in top right corner?

如何使DIV始終浮在屏幕的右上角,這樣即使我向下滾動頁面,DIV仍會顯示在同一個固定位置? 謝謝。

使用position: fixed ,並將其錨定到頁面的topright

#fixed-div {
    position: fixed;
    top: 1em;
    right: 1em;
}

IE6不支持position: fixed 如果你在IE6中需要這個功能, 這個純粹的CSS解決方案似乎可以解決問題 您需要一個包裝器<div>來包含一些樣式才能工作,如樣式表中所示

使用position:fixed ,如前所述,IE6無法識別position:fixed ,但有了一些css魔法你可以讓IE6表現:

html, body {
    height: 100%;
    overflow:auto;
}
body #fixedElement {
    position:fixed !important;
    position: absolute; /*ie6 */
    bottom: 0;
}

!important標志使得您不必對IE使用條件注釋。 這將有#fixedElement使用position:fixed在所有瀏覽器中position:fixed但IE,在IEposition:absolute將生效, bottom:0 這將模擬position:fixed為IE6 position:fixed

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM