Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

css

How do I make a DIV always float on the screen's top right corner, so that even when I scroll the page down, the DIV still shows up in the same fixed location? Thanks.

like image 680
akanevsky Avatar asked Nov 21 '10 02:11

akanevsky


People also ask

How do you make a div appear on top of everything else on the screen?

Set the DIV's z-index to one larger than the other DIVs. You'll also need to make sure the DIV has a position other than static set on it, too. position relative and z index set to 999999999999999999999999999999999999999999999999999.

How do I move a div to a right corner?

If you want to move the div container, make sure the container is set as position "relative." Then adding style="float: right;" will work. If you want to only move the div within that container, then you need to use float="right" on that particular element (object) instead of positioning it with a style.


1 Answers

Use position: fixed, and anchor it to the top and right sides of the page:

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

IE6 does not support position: fixed, however. If you need this functionality in IE6, this purely-CSS solution seems to do the trick. You'll need a wrapper <div> to contain some of the styles for it to work, as seen in the stylesheet.

like image 162
BoltClock Avatar answered Sep 21 '22 08:09

BoltClock