8

I have a div with position:fixed, as the image below suggests.

I want it to be fixed vertically, but I want it to scroll horizontally with the rest of the content (notice the horizontal scroll bar).

Is this possible with CSS? Or do I need Javascript (in this case, how could I do it)?

enter image description here

John Assymptoth
  • 8,227
  • 12
  • 49
  • 68
  • 4
    possible duplicate of [CSS: fixed position on x-axis but not y?](http://stackoverflow.com/questions/2049845/css-fixed-position-on-x-axis-but-not-y) – kapa Jan 18 '12 at 15:32

3 Answers3

6

Old question, but I was also looking for a solution also, and found a nice simple jquery solution, and figured someone else might find it helpful if nothing else:

    $(window).scroll(function(){
        $('#header').css('left', originalLeft - $(this).scrollLeft());
    });

with header being the div, and originalLeft being, well, the initial left:position. This also works if someone scrolls and then zooms out, such that it would go where you would want it to.

Fewfre
  • 1,461
  • 3
  • 19
  • 32
3

You need javascript. Here you can read a tutorial (with mootools): http://www.rickyh.co.uk/css-position-x-and-position-y/. Here a similar question, solved with jquery: CSS: fixed position on x-axis but not y?

Community
  • 1
  • 1
Alessandro Pezzato
  • 8,603
  • 5
  • 45
  • 63
1

you can do it by css itself:

<div style="width:250px; height:250px; border:solid;overflow:scroll; overflow-y:hidden">
    <div style="width:500px; height:500px; border:solid;"></div>
</div>
Dhaval Shukla
  • 1,127
  • 2
  • 10
  • 19
  • 1
    The problem with this solution is that the scroll bar appears right next to the div... I would want the scroll bar to appear in the bottom of the browser. – John Assymptoth Jan 18 '12 at 15:58