بدنه جدول (tbody)
تگ «tbody» بدنه جدول را گروه بندی می کند. «بدنه جدول (Table Body)» یعنی ردیف های اصلیِ داده. مثل سطرهای نمره ها در کارنامه، جدا از عنوان و جمع بندی.
تعریف و جای درستِ استفاده
«بدنه جدول (tbody)» بخشی از جدول است. کنارِ «سربرگ (thead)» و «پاورقی (tfoot)» می آید. مرورگر می تواند بدنه را جدا اسکرول کند.
همیشه <tbody> بعد از <caption>، <colgroup> و <thead> باشد. داخلش حتماً یک یا چند <tr> قرار بده.
برای آشنایی با ساختار کامل، صفحه جدول (table) و سربرگ (thead) و پاورقی (tfoot) را ببین.
مثال: جدول با thead، tbody و tfoot
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
</table>
استایل دهی بخش ها با CSS
<html>
<head>
<style>
thead {
color: green;
}
tbody {
color: blue;
}
tfoot {
color: red;
}
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
</table>
</body>
</html>
تراز متن داخل tbody
<table style="width:100%;">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody style="text-align:right;">
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
تراز عمودی در tbody
<table style="width:50%;">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tbody style="vertical-align:bottom;">
<tr style="height:100px;">
<td>January</td>
<td>$100</td>
</tr>
<tr style="height:100px;">
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
مقادیر پیش فرض CSS برای tbody
tbody {
display: table-row-group;
vertical-align: middle;
border-color: inherit;
}
نکته: از tr برای سطرها و از td برای خانه ها استفاده کن. همچنین لینک بدنه جدول (tbody) همیشه مرجع سریع تو است.
جمع بندی سریع
- tbody بدنه داده های جدول است.
- همیشه بعد thead و قبلِ tfoot بیاید.
- داخل tbody فقط سطرهای tr می آیند.
- می توان تراز افقی و عمودی داد.
- اسکرول بدنه مستقل ممکن است.