[英]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.