[英]Adjust HTML table colum size both with percent and fixed sizes?
干得好:
#fixed{ table-layout:fixed; } td{ border:1px solid red; } td:nth-child(even){ background-color: grey; }
<table id="fixed" border="0" style="width:100%;border-collapse:collapse;"> <tr> <td style="width:50px;">1</td> <!--Fixed width--> <td style="width:50%">Title</td> <td style="width:50%">Interpret</td> <td style="width:20px">1</td> </tr> </table>
我能理解的是,您可以通過應用帶有table
styles
來實現這一點,即table-layout: fixed;
和width:100%;
. 還有使用px
和%
的td
width
。 根據您的設計,您使用了四列,而我為這四列編寫了代碼; 以下將是您的 CSS;
table { table-layout: fixed; width: 100%; } td:first-child { width: 50px; } td:last-child { width: 20px; } .second-column { width: 50%; } .third-column { width: 50%; } td:nth-child(odd) { background-color: grey; } td:nth-child(even) { background-color: silver; }
<table> <tr> <td>1</td> <td class="second-column">2</td> <td class="third-column">3</td> <td>4</td> </tr> </table>
希望這是你所需要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.