[英]Is there a way to configure the width of columns in a table by the number of columns?
我在创建列的 php 中创建一个带有 foreach 循环的表。 是否有可能为列提供均匀的宽度,如 3 列 -> 列宽 33%、4 列 -> 25%、5 列 -> 20% 等等? 现在感觉列的宽度是随机的。
如果你需要一些代码:
PHP/HTML
echo '<tr>';
$permgroups = $perms->getPermissiongroups();
foreach ($permgroups as $group) {
if ($group != "user_ID") {
echo '<th>'.$group.'</th>';
}
}
echo '</tr>';
CSS
.structure_content table {
margin-top: 10px;
margin-bottom: 10px;
line-height: 30px;
background: #BDBDBD;
width: 100%;
float: right;
border-top: 1px solid #CEDADC;
border-bottom: 1px solid #CEDADC;
}
.structure_content th {
font-size: 20px;
}
只需给您的表格table-layout:fixed
....
table { table-layout:fixed; width:100%; margin-bottom: 1em; } td { padding:.5em; border:1px solid red; }
<table> <tr> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> </tr> </table> <table> <tr> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> </tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.