[英]How to center align two table side by side?
我似乎無法將 html 中的 2 個內聯表居中對齊。
我的代碼片段:
<div class="sometables" style="margin-left: auto; margin-right: auto;">
<table style="display:inline-table;float:left;width:30%;margin-right:230px;">
<tr>
<th>Application<br>Processed</th>
<th>Application<br>ID</th>
<th>Last Name</th>
<th>First Name</th>
</tr>
{% for processed in processed_data %}
<tr>
<td>{{processed[0]}}</td>
<td>{{processed[3]}}</td>
<td>{{processed[1]}}</td>
<td>{{processed[2]}}</td>
</tr>
{% endfor %}
</table>
<table style="display:inline-table;float:left;width:30%;">
<tr>
<th>Application<br>Flagged</th>
<th>Application<br>ID</th>
<th>Last Name</th>
<th>First Name</th>
</tr>
{% for flagged in flagged_data %}
<tr>
<td>{{flagged[0]}}</td>
<td>{{flagged[3]}}</td>
<td>{{flagged[1]}}</td>
<td>{{flagged[2]}}</td>
</tr>
{% endfor %}
</table>
</div>
當前output是:
如何將兩個表居中對齊?
研究和盡職調查:
根據 OP 對代碼的請求,未檢查,因為它無法在運行時執行。
刪除對內聯margin
的引用並創建一個基本的 CSS Grid parent .sometables
,它被拉伸以填充其父級(可能是body
)並在兩個子元素( table
)之間添加一些方便的間距,其中包含column-gap
(任何首選值都可以) ).
注意刪除margin
定義...
更新CSS 網格需要一個grid-template-columns
定義來並排顯示表格,而不是堆疊在一起。 每個表獲得總可用空間的1fr
(一小部分)。
確保訪問Grid by Example ,非常值得您花時間。
.sometables { /* CSS Grid settings */ display: grid; place-items: center; grid-template-columns: 1fr 1fr; column-gap: 2em; width: 100%; /* to fill full width of parent */ }
<div class="sometables"> <table style="display:inline-table;float:left;width:30%;"> <tr> <th>Application<br>Processed</th> <th>Application<br>ID</th> <th>Last Name</th> <th>First Name</th> </tr> {% for processed in processed_data %} <tr> <td>{{processed[0]}}</td> <td>{{processed[3]}}</td> <td>{{processed[1]}}</td> <td>{{processed[2]}}</td> </tr> {% endfor %} </table> <table style="display:inline-table;float:left;width:30%;"> <tr> <th>Application<br>Flagged</th> <th>Application<br>ID</th> <th>Last Name</th> <th>First Name</th> </tr> {% for flagged in flagged_data %} <tr> <td>{{flagged[0]}}</td> <td>{{flagged[3]}}</td> <td>{{flagged[1]}}</td> <td>{{flagged[2]}}</td> </tr> {% endfor %} </table> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.