Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not an easy one. I've come up with a Script solution. (I don't think this can be done using pure CSS)</p> <p>the <strong>HTML</strong> stays the same as you posted, the <strong>CSS</strong> changes a little bit, <strong>JQuery</strong> code added.</p> <p><a href="http://jsfiddle.net/avrahamcool/eZXtq/"><strong>Working Fiddle</strong></a> <em>Tested on:</em> IE10, IE9, IE8, FF, Chrome</p> <p>BTW: if you have unique elements, why don't you use id's instead of classes? I think it gives a better selector performance.</p> <p><strong>Explanation</strong> of how it works: <code>inner-container</code> will span the entire space of the <code>outer-container</code> (so basically, he's not needed) but I left him there, so you wont need to change you DOM.</p> <p>the <code>table-header</code> is relatively positioned, without a scroll (<code>overflow: hidden</code>), we will handle his scroll later.</p> <p>the <code>table-body</code> have to span the rest of the <code>inner-container</code> height, so I used a script to determine what height to fix him. (it changes dynamically when you re-size the window) without a fixed height, the scroll wont appear, because the div will just grow large instead.. notice that this part can be done without script, if you fix the header height and use CSS3 (as shown in the end of the answer)</p> <p>now it's just a matter of moving the header along with the body each time we scroll. this is done by a function assigned to the <code>scroll</code> event.</p> <p><strong>CSS</strong> (some of it was copied from your style)</p> <pre><code>* { padding: 0; margin: 0; } body { height: 100%; width: 100%; } table { border-collapse: collapse; /* make simple 1px lines borders if border defined */ } .outer-container { background-color: #ccc; position: absolute; top:0; left: 0; right: 300px; bottom: 40px; } .inner-container { height: 100%; overflow: hidden; } .table-header { position: relative; } .table-body { overflow: auto; } .header-cell { background-color: yellow; text-align: left; height: 40px; } .body-cell { background-color: blue; text-align: left; } .col1, .col3, .col4, .col5 { width:120px; min-width: 120px; } .col2 { min-width: 300px; } </code></pre> <p><strong>JQuery</strong></p> <pre><code>$(document).ready(function () { setTableBody(); $(window).resize(setTableBody); $(".table-body").scroll(function () { $(".table-header").offset({ left: -1*this.scrollLeft }); }); }); function setTableBody() { $(".table-body").height($(".inner-container").height() - $(".table-header").height()); } </code></pre> <p>If you don't care about fixing the header height (I saw that you fixed the cell's height in your CSS), some of the Script can be skiped if you use CSS3 :<a href="http://jsfiddle.net/avrahamcool/eZXtq/1/"><strong>Shorter Fiddle</strong></a> (this will not work on IE8)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload