2017-09-14 2 views
0

ポストHTML table with 100% width, with vertical scroll inside tbodyのHashem Qolamiによって投稿されたソリューションを試しましたが、問題があります。幅100%のHTMLテーブル、縦スクロールの内側にtbd wdthなし

Tried Scenario-Issue

場合には、追加の詳細情報を必要とし、私はあなたを記入してみましょう。

複数の投稿を試しました。どこでもにtdの固定幅しか見つかりませんでした。しかし、私はtbodyのデータによると、動的な幅が必要です。

js、cssの異なるセクションがある場合、サイトで作業しています。 しかし、私はすべてを1つのhtmlにまとめると動作しません。 私のHTMLイメージ:HTML Image

// 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(); 
 
    alert("hii"); 
 
    }).get(); 
 

 
    // Set the width of thead columns 
 
    $table.find('thead tr').children().each(function(i, v) { 
 
    $(v).width(colWidth[i]); 
 
    }); 
 
}).resize(); // Trigger resize handler
table.scroll { 
 
    /* width: 100%; */ 
 
    /* Optional */ 
 
    /* border-collapse: collapse; */ 
 
    border-spacing: 0; 
 
    border: 2px solid black; 
 
} 
 

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

 
thead tr th { 
 
    height: 30px; 
 
    line-height: 30px; 
 
    /* text-align: left; */ 
 
} 
 

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

 
tbody { 
 
    border-top: 2px solid black; 
 
} 
 

 
tbody td, 
 
thead th { 
 
    /* width: 20%; */ 
 
    /* Optional */ 
 
    border-right: 1px solid black; 
 
    /* white-space: nowrap; */ 
 
} 
 

 
tbody td:last-child, 
 
thead th:last-child { 
 
    border-right: none; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
 

 
<table class="scroll"> 
 
    <thead> 
 
    <tr> 
 
     <th>Head 1</th> 
 
     <th>Head 2</th> 
 
     <th>Head 3</th> 
 
     <th>Head 4</th> 
 
     <th>Head 5</th> 
 
    </tr> 
 
    </thead> 
 
    <tbody> 
 
    <tr> 
 
     <td>Content 1</td> 
 
     <td>Content 2</td> 
 
     <td>Content 3</td> 
 
     <td>Content 4</td> 
 
     <td>Content 5</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Content 1</td> 
 
     <td>Lorem ipsum dolor sit amet.</td> 
 
     <td>Content 3</td> 
 
     <td>Content 4</td> 
 
     <td>Content 5</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Content 1</td> 
 
     <td>Content 2</td> 
 
     <td>Content 3</td> 
 
     <td>Content 4</td> 
 
     <td>Content 5</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Content 1</td> 
 
     <td>Content 2</td> 
 
     <td>Content 3</td> 
 
     <td>Content 4</td> 
 
     <td>Content 5</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Content 1</td> 
 
     <td>Content 2</td> 
 
     <td>Content 3</td> 
 
     <td>Content 4</td> 
 
     <td>Content 5</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Content 1</td> 
 
     <td>Content 2</td> 
 
     <td>Content 3</td> 
 
     <td>Content 4</td> 
 
     <td>Content 5</td> 
 
    </tr> 
 
    <tr> 
 
     <td>Content 1</td> 
 
     <td>Content 2</td> 
 
     <td>Content 3</td> 
 
     <td>Content 4</td> 
 
     <td>Content 5</td> 
 
    </tr> 
 
    </tbody> 
 
</table>

答えて

4

コメントを解除し、あなたのテーブルの幅

table.scroll { 
    width: 100%; 
    /* Optional */ 
    /* border-collapse: collapse; */ 
    border-spacing: 0; 
    border: 2px solid black; 
} 

は、サイズを変更する場合this

細胞がそれに応じて応答しているしてみてください。

+0

あなたのhelp.butのためにありがとう私は私が何か間違っている間違っていることを確かめてください.HTML全体を実行しようとしています.NTの仕事をしています。これらのコードテンプレートの他のソースを使用しようとしています。私はHTMLのスクリーンショットを編集の画像として追加しました。 – Harry

関連する問題