简体   繁体   中英

CSS/Javascript element vertically fixed between 2 coordinates

I would like to make a div that is fixed vertically but after a point (a coordinate for instance) he stops following and stays where he is. thanks for answers!!

Based on your edited question and question tags, I assume you want to make a fixed position div to stay at a particular position even when you are scrolling.

(And maybe you have done it already but it does not work, if that's the case please provide some related code)

This can be done by setting the div's position and the top/right/bottom/left in css.

#my_div{
position: fixed;
top: 0px; 
left: 0px;
}

This will set your div fixed on the window's top-left corner no matter what.

Here's a short but clear tutorial on css positioning, have a look if you have some time :)

Learn CSS Positioning in Ten Steps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM