Reputation: 3671
How can I position a div anywhere on a page? I'm trying to treat it as a popup box. Below is what happens when I use the following code:
<div style="width: 100px;padding: 5px; background-color: #CCCCCC;top: 73px; left: 0px">TEST</div>
Upvotes: 1
Views: 7484
Reputation: 2362
position: absolute; will not work as you expect when the user has scrolled down on the page. You'll want to also look at position:fixed, which will position an element relative to the "viewport" (the browser window, no matter where the user has scrolled).
Upvotes: 0
Reputation: 68922
You need to know more about CSS Positioning.
In your case you can use either position:absolute;
or position:fixed;
based on your needs.
Upvotes: 0
Reputation: 43820
giv the body an position: relative
and the div a position: absolute
This way the div will can be positioned anywhere relative to the body, using top and left properties.
In cases like these it makes more sense to use the css in the head or external file.
Upvotes: 0
Reputation: 11538
Use absolute positioning:
style="position:absolute; top:10px; left:10px"
the top
and left
are the x,y coordinates of the top left edge of your div.
Upvotes: 7