admin管理员组

文章数量:1415673

Case example: I have a long list of items, and when I put my mouse over this div changes to that picture of that item. No matter where you scroll to, the div remains in a fixed position.

Sort of like a frame.

Case example: I have a long list of items, and when I put my mouse over this div changes to that picture of that item. No matter where you scroll to, the div remains in a fixed position.

Sort of like a frame.

Share Improve this question asked Apr 17, 2010 at 8:41 fivetwentysixfivetwentysix 7,4959 gold badges42 silver badges59 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 3

Use the CSS property position:fixed.

Example: <div id="items" style="position: fixed; top: 20px; right: 20px">Hello there!</div>

the div remains in a fixed position.

position: fixed? Test it here.

For newer browsers you can use position:fixed to make an element follow the window when you scroll.

If you need to be patible with older browsers, you would need a Javascript that gets the scroll offset from the window and changes the coordinates of an absolutely positioned element.

Absolute positioning:

<body>
    <div style="position: absolute; top: 0; right: 0; width: 100px; height: 100px;">
    </div>
</body>

Are you asking about div in fixed position? If you want to this the div by css itself, you can use the paramater like

height:0px;
left:0px;
position:absolute;
top:0px;
width:0px;
z-index:1;

本文标签: