I created a div
element, that I placed all the way on the right of my site. The only problem is that its at the top of the site, so if i scroll down it remains there.
How can I force it to remain in the same part of the page, when page is being scrolled?
This is, what I've managed to figure out myself so far:
<div style="width: 200px; background-color: #999; z-index: 10; position: absolute; right: 0; top: 0; height: 83px;"> </div>
Use position fixed. Position fixed makes it so that an element stays at it's specified place even if the user scrolls up or down.
You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.
A fixed position element is positioned relative to the viewport, or the browser window itself. The viewport doesn't change when the window is scrolled, so a fixed positioned element will stay right where it is when the page is scrolled.
Change position:absolute
to position:fixed;
.
Example can be found in this jsFiddle.
Use position: fixed
instead of position: absolute
.
See here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With