vertical bootstrap html css header html-table fixed

html - bootstrap - sticky header jquery



Se corrigiĆ³ la tabla de encabezado con la barra de desplazamiento horizontal y la barra de desplazamiento vertical en (8)

He estado tratando de resolver este problema que tengo con html / css sticky header + scrollbars. Estamos creando un programa que requiere que las barras de desplazamiento se muestren una vez que el contenedor llegue a cierto punto (según la resolución del usuario).

Estoy forzando un ancho mínimo en la segunda columna de la tabla, por lo que la tabla deja de disminuir en un cierto punto y obliga al contenedor a permanecer en un cierto ancho. El desbordamiento en el contenedor muestra la barra de desplazamiento horizontal. Todo funciona bien Una vez que agrego una segunda barra de desplazamiento para el desplazamiento vertical, las cosas se ensucian. ¿Alguien tiene una solución para este problema? Quiero tener una barra de desplazamiento vertical en .table-body, pero la barra de desplazamiento debe estar visible en el contenedor externo.

¿Hay una buena solución html / css para tablas de encabezado fijo? He estado buscando durante una semana, pero solo puedo encontrar complementos jQuery para este tipo de comportamiento.

Este es mi HTML actual:

<!DOCTYPE html> <html> <head> <title>fixed header prototyping</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <div class="outer-container"> <!-- absolute positioned container --> <div class="inner-container"> <div class="table-header"> <table id="headertable" width="100%" cellpadding="0" cellspacing="0"> <thead> <tr> <th class="header-cell col1">One</th> <th class="header-cell col2">Two</th> <th class="header-cell col3">Three</th> <th class="header-cell col4">Four</th> <th class="header-cell col5">Five</th> </tr> </thead> </table> </div> <div class="table-body"> <table id="bodytable" width="100%" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> </tbody> </table> </div> </div> </div> </body> </html>

Y mi CSS se ve así:

body { margin:0; padding:0; height: 100%; width: 100%; } table { border-collapse: collapse; /* make simple 1px lines borders if border defined */ } tr { width: 100%; } .outer-container { background-color: #ccc; position: absolute; top:0; left: 0; right: 300px; bottom:40px; overflow: hidden; } .inner-container { width: 100%; height: 100%; position: relative; overflow-x: scroll; overflow-y:hidden; } .table-header { float:left; width: 100%; } .table-body { float:left; height: 100%; width: inherit; overflow-y: scroll; } .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; }

Ejemplo JSFiddle - http://jsfiddle.net/W8URM/

Gracias de antemano chicos!


Aquí hay una solución HTML / CSS única.

Disculpe la respuesta a la pregunta después de tanto tiempo, pero la solución dada no me satisfizo y encontré una mejor. Esta es la forma más fácil de hacerlo con HTML (sin jquery):

Antes de eso, la solución violó la pregunta. https://jsfiddle.net/3vzrunkt/

<div> <div style="overflow:hidden;;margin-right:16px" id="headerdiv"> <table id="headertable" style="min-width:900px" border=1> <thead> <tr> <th style="width:120px;min-width:120px;">One</th> <th style="width:420px;min-width:420px;">Two</th> <th style="width:120px;min-width:120px;">Three</th> <th style="width:120px;min-width:120px;">Four</th> <th style="width:120px;min-width:120px;">Five</th> </tr> </thead> </table> </div> <div style="overflow-y:scroll;max-height:200px;" onscroll="document.getElementById(''headerdiv'').scrollLeft = this.scrollLeft;"> <table id="bodytable" border=1 style="min-width:900px; border:1px solid"> <tbody> <tr> <td style="width:120px;min-width:120px;">body row1</td> <td style="width:420px;min-width:420px;">body row2</td> <td style="width:120px;min-width:120px;">body row2</td> <td style="width:120px;min-width:120px;">body row2</td> <td style="width:120px;min-width:120px;">body row2 en nog meer</td> </tr> : : : : </tbody> </table> </div> </div>

Y para explicar la solución:

  1. usted necesita y adjuntando div sin desbordamiento / desplazamiento requerido

  2. un encabezado div que contiene la tabla de encabezado con desbordamiento: oculto para garantizar que no se visualice la barra de desplazamiento. Agregue margen-derecha: 16px para asegurarse de que la barra de desplazamiento quede afuera mientras se sincroniza.

  3. otro div para contener los registros de la tabla y overflow-y: scroll. Tenga en cuenta que se requiere el relleno para hacer que la barra de desplazamiento se mueva hacia la derecha del encabezado.

  4. Y lo más importante es el js mágico para sincronizar los datos del encabezado y la tabla:

    onscroll="document.getElementById(''headerdiv'').scrollLeft = this.scrollLeft;"


Aquí hay una solución que nuevamente no es una solución de solo CSS . Es similar a la solución de avrahamcool ya que utiliza unas pocas líneas de jQuery, pero en lugar de cambiar las alturas y mover el encabezado, todo lo que hace es cambiar el ancho de tbody función de la distancia a la que se desplaza la table padre derecho.

Una ventaja adicional con esta solución es que funciona con una tabla HTML semánticamente válida .

Funciona muy bien en todas las versiones recientes de navegador (IE10, Chrome, FF) y eso es todo, la funcionalidad de desplazamiento se rompe en las versiones anteriores.

Pero el hecho de que esté utilizando una tabla HTML semánticamente válida salvará el día y se asegurará de que la tabla se muestre correctamente, solo funciona con el desplazamiento que no funcionará en los navegadores más antiguos.

Aquí hay un jsFiddle para demostración.

CSS

table { width: 300px; overflow-x: scroll; display: block; } thead, tbody { display: block; } tbody { overflow-y: scroll; overflow-x: hidden; height: 140px; } td, th { min-width: 100px; }

JS

$("table").on("scroll", function () { $("table > *").width($("table").width() + $("table").scrollLeft()); });

Necesitaba una versión que se degrada muy bien en IE9 (sin desplazamiento, solo una tabla normal). Publicando el violín aquí, ya que es una versión mejorada. Todo lo que necesitas hacer es establecer una altura en el tr .

CSS adicional para hacer que esta solución se degrade muy bien en IE9

tr { height: 25px; /* This could be any value, it just needs to be set. */ }

Aquí hay un jsFiddle demuestra la degradación agradable en la versión IE9 de esta solución.

Editar : enlaces de violín actualizados para vincular a una versión del violín que contiene correcciones para problemas mencionados en los comentarios. Solo agrego un fragmento con la versión más reciente y excelente mientras estoy en ello:

$(''table'').on(''scroll'', function() { $("table > *").width($("table").width() + $("table").scrollLeft()); });

html { font-family: verdana; font-size: 10pt; line-height: 25px; } table { border-collapse: collapse; width: 300px; overflow-x: scroll; display: block; } thead { background-color: #EFEFEF; } thead, tbody { display: block; } tbody { overflow-y: scroll; overflow-x: hidden; height: 140px; } td, th { min-width: 100px; height: 25px; border: dashed 1px lightblue; overflow: hidden; text-overflow: ellipsis; max-width: 100px; }

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>AAAAAAAAAAAAAAAAAAAAAAAAAA</td> <td>Row 1</td> <td>Row 1</td> <td>Row 1</td> <td>Row 1</td> </tr> <tr> <td>Row 2</td> <td>Row 2</td> <td>Row 2</td> <td>Row 2</td> <td>Row 2</td> </tr> <tr> <td>Row 3</td> <td>Row 3</td> <td>Row 3</td> <td>Row 3</td> <td>Row 3</td> </tr> <tr> <td>Row 4</td> <td>Row 4</td> <td>Row 4</td> <td>Row 4</td> <td>Row 4</td> </tr> <tr> <td>Row 5</td> <td>Row 5</td> <td>Row 5</td> <td>Row 5</td> <td>Row 5</td> </tr> <tr> <td>Row 6</td> <td>Row 6</td> <td>Row 6</td> <td>Row 6</td> <td>Row 6</td> </tr> <tr> <td>Row 7</td> <td>Row 7</td> <td>Row 7</td> <td>Row 7</td> <td>Row 7</td> </tr> <tr> <td>Row 8</td> <td>Row 8</td> <td>Row 8</td> <td>Row 8</td> <td>Row 8</td> </tr> <tr> <td>Row 9</td> <td>Row 9</td> <td>Row 9</td> <td>Row 9</td> <td>Row 9</td> </tr> <tr> <td>Row 10</td> <td>Row 10</td> <td>Row 10</td> <td>Row 10</td> <td>Row 10</td> </tr> </tbody> </table>


Esto me ha estado volviendo loco por literalmente semanas. Encontré una solución que funcionará para mí que incluye:

  1. Anchos de columna no fijos: se contraen y crecen al cambiar el tamaño de la ventana.
  2. La tabla tiene una barra de desplazamiento horizontal cuando es necesario, pero no cuando no lo es.
  3. El número de columnas es irrelevante: se ajustará a la cantidad de columnas que lo necesite.
  4. No todas las columnas deben tener el mismo ancho.
  5. El encabezado llega hasta el final de la barra de desplazamiento derecha.
  6. ¡Sin javascript!

... pero hay un par de advertencias:

  1. La barra de desplazamiento vertical no está visible hasta que se desplaza completamente hacia la derecha. Dado que la mayoría de la gente tiene ruedas de desplazamiento, este fue un sacrificio aceptable.

  2. El ancho de la barra de desplazamiento debe ser conocido. En mi sitio web establecí los anchos de la barra de desplazamiento (no me preocupan demasiado los navegadores antiguos e incompatibles), por lo que puedo calcular los anchos de table y div que se ajustan en función de la barra de desplazamiento.

En lugar de publicar mi código aquí, publicaré un enlace al jsFiddle.

Tabla de encabezado fijo + desplazamiento hacia la izquierda / derecha .


Esto no es fácil. He encontrado una solución de Script. (No creo que esto se pueda hacer usando CSS puro)

el HTML permanece igual que el publicado, el CSS cambia un poco, se agregó el código de JQuery .

Fiddle de trabajo probado en: IE10, IE9, IE8, FF, Chrome

Por cierto: si tiene elementos únicos, ¿por qué no usa los identificadores en lugar de las clases? Creo que ofrece un mejor rendimiento en el selector.

Explicación de cómo funciona: inner-container abarcará todo el espacio del outer-container (así que, básicamente, no es necesario), pero lo dejé allí, por lo que no necesitará cambiar su DOM.

el table-header está relativamente posicionado, sin un desplazamiento ( overflow: hidden ), manejaremos su desplazamiento más tarde.

el table-body la table-body tiene que abarcar el resto de la altura del inner-container , así que usé un guión para determinar qué altura arreglarlo. (Cambia dinámicamente cuando cambia el tamaño de la ventana) sin una altura fija, el desplazamiento no aparecerá, porque el div se volverá grande en su lugar ... observe que esta parte se puede hacer sin script, si arregla la altura del encabezado y usa CSS3 (como se muestra al final de la respuesta)

ahora solo se trata de mover el encabezado junto con el cuerpo cada vez que nos desplazamos. esto se hace mediante una función asignada al evento de scroll .

CSS (parte de ella fue copiada de su estilo)

* { 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; }

JQuery

$(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()); }

Si no te importa arreglar la altura del encabezado (vi que arreglaste la altura de la celda en tu CSS), parte del Script se puede esquiar si usas CSS3: Fiddle más corto (esto no funcionará en IE8)


La solución es usar JS para desplazar horizontalmente el div superior de modo que coincida con el div inferior.

Debe tener mucho cuidado para asegurarse de que la parte superior e inferior tengan exactamente los mismos tamaños, por ejemplo, puede que necesite hacer que el TD y el TH utilicen anchuras fijas.

Aquí hay un violín https://jsfiddle.net/jdhenckel/yzjhk08h/5/

Las partes importantes: uso de CSS

.head { overflow-x: hidden; overflow-y: scroll; width: 500px; } .lower { overflow-x: auto; overflow-y: scroll; width: 500px; height: 400px; }

Aviso overflow-y debe ser el mismo tanto en la cabeza como en la parte inferior.

Y el Javascript ...

var head = document.querySelector(''.head''); var lower = document.querySelector(''.lower''); lower.addEventListener(''scroll'', function (e) { console.log(lower.scrollLeft); head.scrollLeft = lower.scrollLeft; });


Si esto es lo que quieres, solo solución HTML y CSS

fiddle

Aquí está el HTML

<div class="outer-container"> <!-- absolute positioned container --> <div class="inner-container"> <div class="table-header"> <table id="headertable" width="100%" cellpadding="0" cellspacing="0"> <thead> <tr> <th class="header-cell col1">One</th> <th class="header-cell col2">Two</th> <th class="header-cell col3">Three</th> <th class="header-cell col4">Four</th> <th class="header-cell col5">Five</th> </tr> </thead> </table> </div> <div class="table-body"> <table id="bodytable" width="100%" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> <tr> <td class="body-cell col1">body row1</td> <td class="body-cell col2">body row2</td> <td class="body-cell col3">body row2</td> <td class="body-cell col4">body row2</td> <td class="body-cell col5">body row2 en nog meer</td> </tr> </tbody> </table> </div> </div> </div>

Y este es el CSS

body { margin:0; padding:0; height: 100%; width: 100%; } table { border-collapse: collapse; /* make simple 1px lines borders if border defined */ } tr { width: 100%; } .outer-container { background-color: #ccc; position: absolute; top:0; left: 0; right: 300px; bottom:40px; overflow: scroll; } .inner-container { width: 100%; height: 100%; position: relative; overflow-x: visible; overflow-y:visible; } .table-header { float:left; width: 100%; } .table-body { float:left; height: auto; width: auto; overflow: visible; background-color: red; } .header-cell { background-color: yellow; text-align: left; height: 40px; } .body-cell { background-color: transparent; text-align: left; } .col1, .col3, .col4, .col5 { width:120px; min-width: 120px; } .col2 { min-width: 300px; }

Avísame si esto es lo que necesitas. O algo falta. Revisé las otras respuestas y descubrí que se ha usado jquery. Lo tomé en la suposición de que necesitas una solución CSS. Si me falta algo más, por favor menciona :)


puedes usar el siguiente código CSS ...

body { margin:0; padding:0; height: 100%; width: 100%; } table { border-collapse: collapse; /* make simple 1px lines borders if border defined */ } tr { width: 100%; } .outer-container { background-color: #ccc; top:0; left: 0; right: 300px; bottom:40px; overflow:hidden; } .inner-container { width: 100%; height: 100%; position: relative; } .table-header { float:left; width: 100%; } .table-body { float:left; height: 100%; width: inherit; } .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; }


ejemplo de trabajo en jsFiddle

Esto se puede lograr usando div. Se puede hacer con la mesa también. Pero siempre prefiero div.

<body id="doc-body" style="width: 100%; height: 100%; overflow: hidden; position: fixed" onload="InitApp()"> <div> <!--If you don''t need header background color you don''t need this div.--> <div id="div-header-hack" style="height: 20px; position: absolute; background-color: gray"></div> <div id="div-header" style="position: absolute; top: 0px; overflow: hidden; height: 20px; background-color: gray"> </div> <div id="div-item" style="position: absolute; top: 20px; overflow: auto" onscroll="ScrollHeader()"> </div> </div> </body>

Javascript:
Consulte jsFiddle para esta parte. De lo contrario, esta respuesta se vuelve muy larga.