[英]How to make a DIV always float on the screen in top right corner?
如何使DIV始終浮在屏幕的右上角,這樣即使我向下滾動頁面,DIV仍會顯示在同一個固定位置? 謝謝。
使用position: fixed
,並將其錨定到頁面的top
和right
:
#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,在IE
, position:absolute
將生效, bottom:0
。 這將模擬position:fixed
為IE6 position:fixed
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.