2017-10-27 17 views
1

スクロール可能なテーブルを作成しようとしています。テーブルがHTMLで表示されないようにしたい

ただし、enter image description hereと表示されています。

スクロールでenter image description hereとしたいと思いました。

私が試した:

<style> 
table.scroll tbody, 
table.scroll thead { display: block; } 



table.scroll tbody { 
    height: 300px; 
    overflow-y: auto; 
    overflow-x: hidden; 
} 

</style> 
<script> 
// Change the selector if needed 
var $table = $('table.scroll'), 
    $bodyCells = $table.find('tbody tr:first').children(), 
    colWidth; 

// Adjust the width of thead cells when window resizes 
$(window).resize(function() { 
    // Get the tbody columns width array 
    colWidth = $bodyCells.map(function() { 
     return $(this).width(); 
    }).get(); 

    // Set the width of thead columns 
    $table.find('thead tr').children().each(function(i, v) { 
     $(v).width(colWidth[i]); 
    });  
}).resize(); // Trigger resize handler 
</script> 

私はあなたがすべてを正しく合わせることでtbody

答えて

0

を効果をスクロールしているテーブルは、あなたがやった理由であるメインテーブル に幅を与えるのを忘れたいです必要な出力が これはテーブルに完全な幅aを与える

table.scroll,table{width:100%;} 

を試してみてください取得ND、必要な出力

+0

試しましたが、変更はありません! – MKJ

+0

次にHTMLコードを共有する必要があります –

+0

HTMLコードは次のとおりです。https://www.w3schools.com/code/tryit.asp?filename=FKWXSM4XT960 – MKJ

0

働くかもしれ
table 
{ 
    display: block; 
    overflow-x: auto; 
    white-space: nowrap; 
} 

以下のようにCSSを入れてやってみてしまいます。

+0

試しましたが、変更はありません! – MKJ

+0

また、実際には重複した質問です。このリンクを試すhttps://stackoverflow.com/questions/5533636/add-horizo​​ntal-scrollbar-to-html-table –

+0

https://stackoverflow.com/questions/17067294/html-table-with-100で試してみました-width-with-vertical-scroll-inside-tbodyは、重複することもできますか? – MKJ

関連する問題