[英]How can I code a table with "individually controlled cells" like in the example picture using HTML & CSS?
我一直在網上尋找,但沒有找到任何可以幫助制作這樣一張桌子的東西。 已經嘗試使用colspan
,但它沒有像我希望的那樣工作。
有人有其他想法嗎?
編輯:試過這個
table, td, th { border: 1px solid black; border-collapse: collapse; width: auto; } th { /* text */ padding: 0px; margin: 0px; } td { /* pictures */ padding: 5px; text-align: left; }
<table style="width:100%"> <tr> <td>Month</td> <td colspan="2">Savings</td> </tr> <tr> <td colspan="2">January</td> <td>$100</td> </tr> <tr> <td>February</td> <td colspan="2">$50</td> </tr> </table>
使用 CSS 網格:
.box { border: 1px solid black; display: grid; grid-template-columns: repeat(3, 1fr); } .box div:nth-child(4n + 1), .box div:nth-child(4n + 4) { grid-column: span 2; } .box div { outline: 1px solid; padding: 5px; }
<div class="box"> <div>Month</div> <div>Savings</div> <div>January</div> <div>$100</div> <div>February</div> <div>$50</div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.