I'm looking for a way that I can create a div that will be fixed vertically on the page, so if the user scrolls down, the div stays in the same place on the page. But adjust it horizontally, so if the userβs screen is narrower than my web page, scrolling to the right or left will not cause the div to move from the screen and in some cases will remain either half visible at the edge of the screen or completely leave the page.
This div should be in the "Position: Relative" section.
I am sure that there is no way to assign different positions for the changing axis of the div, but this is the best way to describe the effect that I hope to achieve.
I have it so far, basically it is a fixed div within a relative div.
CSS
#container { position:relative; width:700px; height:1000px; top:50px; left:50px; background-color:yellow; }
HTML
<div id="container"> <div id="blue-box"></div> </div>
I also created jsFiddle to demonstrate this problem.
This works great for vertical, but if you resize your web browser so that it is smaller than the yellow box (container) and then scrolled horizontally, the blue box will move with the page. I hope this does not happen.
If this cannot be done using CSS, I would love to use JavaScript if it works with all modern browsers and IE7 and IE8. (This is why I added the JavaScript tag)
Can anyone help me out?
javascript css scroll css-position
Flickdraw
source share