I have two lines of data (green) and a header (red) that should be visible at any time:
Check out the example that I already have:
http://jsfiddle.net/j9C8R/33/
This is my current HTML:
<div class="main"> <div class="row"> <div class="sticky">Sticky header A</div> <div class="content">ContentA</div> <div class="content">ContentA</div> <div class="content">ContentA</div> <div class="content">ContentA</div> </div> <div class="row"> <div class="sticky">Sticky header B</div> <div class="content">ContentB</div> <div class="content">ContentB</div> <div class="content">ContentB</div> <div class="content">ContentB</div> </div> <div class="row"> <div class="sticky">Sticky header C</div> <div class="content">ContentC</div> <div class="content">ContentC</div> <div class="content">ContentC</div> <div class="content">ContentC</div> </div> <div class="row"> <div class="sticky">Sticky header D</div> <div class="content">ContentD</div> <div class="content">ContentD</div> <div class="content">ContentD</div> <div class="content">ContentD</div> </div> <div class="row"> <div class="sticky">Sticky header E</div> <div class="content">ContentE</div> <div class="content">ContentE</div> <div class="content">ContentE</div> <div class="content">ContentE</div> </div> </div>
And CSS:
.main { background-color:blue; overflow:scroll; height:200px; width:400px; } .row { height:50px; overflow:scroll; clear:both; width:1000px; background-color:yellow; } .sticky, .content { float:left; width:150px; border:1px solid black; } .sticky { background-color:red; } .content { background-color:green; }
Now the red title scrolls along with the content, but it should adhere to where it is now, but scroll vertically with the content (MS Excel style).
How this can be achieved (preferably only with CSS).
UPDATE . It is important that the red headers scroll vertically along with the corresponding content, but when scrolling horizontally adhere to the left edge.
source share