Reputation: 8942
I am trying to center span
in tbody
, but I am not sure how to do that and I don't know if this structure is valid if I don't include a tr
and td
elements.
html
<table class="table">
<thead>
<tr>
<th>Rank</th>
<th>
<div>Name</div>
</th>
<th>
<div>Age</div>
</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<div><span>You haven’t added any data yet</span></div>
</tbody>
</table>
css
tbody div {
display: table-row;
}
tbody div span{
display: block;
text-align: center;
width: 100%;
}
Upvotes: 1
Views: 1066
Reputation: 1826
By convention you should include tr and th as well within tbody
You can use colspan
to merge columns and text-align:center
style to center text.
<table class="table" style="width:100%">
<thead>
<tr>
<th>Rank</th>
<th>
<div>Name</div>
</th>
<th>
<div>Age</div>
</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="4" style="text-align: center;">You haven’t added any data yet</td>
</tr>
</tbody>
</table>
Upvotes: 0
Reputation: 11889
Use colspan:
<table class="table">
<thead>
<tr>
<th>Rank</th>
<th>
<div>Name</div>
</th>
<th>
<div>Age</div>
</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">You haven’t added any data yet</td>
</tr>
</tbody>
</table>
Upvotes: 2