[英]HTML Table fit screen height
So this is how my page look like right now (the colors is just to see the containers):所以这就是我的页面现在的样子(colors 只是为了查看容器):
This is my PHP code:这是我的 PHP 代码:
<div class="containerrr">
<div class="wrapperrr">
<center><h4>Leaderboard uke</h4></center>
<table>
<thead>
<tr>
<th>Nr.</th>
<th></th>
<th>Navn</th>
<th>Salg</th>
</tr>
</thead>
<tbody>
<?php
$currentRow = 0;
foreach($link->query('SELECT idn,COUNT(*) FROM usr') as $row) {
echo "<tr>";
$currentRow++;
if ($currentRow == 1) {
echo "<td>🥇</td>";
}
if ($currentRow == 2) {
echo "<td>🥈</td>";
}
if ($currentRow == 3) {
echo "<td>🥉</td>";
}
if ($currentRow > 3) {
echo "<td>$currentRow</td>";
}
echo "<td><img alt='Avatar' class='avatar' src='img.png'/></td>";
$sql = "SELECT * FROM usr WHERE idn='{$row['idn']}'";
$resultt = $link->query($sql);
if ($resultt->num_rows > 0) {
while($roww = $resultt->fetch_assoc()) {
echo "<td>" . $roww['fullname'] . "</td>";
}
}
echo "<td>" . $row['COUNT(*)'] . "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
CSS: CSS:
.containerrr {
background-color: red;
height: 900px;
position: relative;
}
.containerrr > header {
margin: 0 auto;
padding: 1em;
text-align: center;
}
.containerrr > header h1 {
font-weight: 600;
font-size: 3em;
margin: 0;
}
.wrapperrr {
line-height: 1.5em;
margin: 0 auto;
padding: 2em 0 3em;
width: 90%;
max-width: 2000px;
background-color: blue;
height: 100%;
}
table {
border-collapse: collapse;
width: 100%;
background: #fff;
table-layout: auto;
}
I want the table to fit the container(red color).我希望桌子适合容器(红色)。 But now I need to scroll down to see all the table data.
但现在我需要向下滚动才能查看所有表格数据。 How can I resize(in this case make it smaller), so all the rows fits the red area, so I don't have to scroll down?
我怎样才能调整大小(在这种情况下让它变小),所以所有的行都适合红色区域,所以我不必向下滚动? What am I missing here?
我在这里想念什么?
Add display: flex
and flex-direction: column
in containerrr
class.在
containerrr
class 中添加display: flex
和flex-direction: column
。
.containerrr { display: flex; flex-direction: column; background-color: red; height: 900px; position: relative; }.containerrr > header { margin: 0 auto; padding: 1em; text-align: center; }.containerrr > header h1 { font-weight: 600; font-size: 3em; margin: 0; }.wrapperrr { line-height: 1.5em; margin: 0 auto; padding: 2em 0 3em; width: 90%; max-width: 2000px; background-color: blue; height: 100%; } table { border-collapse: collapse; width: 100%; background: #fff; table-layout: auto; }
<div class="containerrr"> <div class="wrapperrr"> <center><h4>Leaderboard uke</h4></center> <table> <thead> <tr> <th>Nr.</th> <th></th> <th>Navn</th> <th>Salg</th> </tr> </thead> <tbody> <?php $currentRow = 0; foreach($link->query('SELECT idn,COUNT(*) FROM usr') as $row) { echo "<tr>"; $currentRow++; if ($currentRow == 1) { echo "<td></td>"; } if ($currentRow == 2) { echo "<td></td>"; } if ($currentRow == 3) { echo "<td></td>"; } if ($currentRow > 3) { echo "<td>$currentRow</td>"; } echo "<td><img alt='Avatar' class='avatar' src='img.png'/></td>"; $sql = "SELECT * FROM usr WHERE idn='{$row['idn']}'"; $resultt = $link->query($sql); if ($resultt->num_rows > 0) { while($roww = $resultt->fetch_assoc()) { echo "<td>". $roww['fullname']. "</td>"; } } echo "<td>". $row['COUNT(*)']. "</td>"; echo "</tr>"; }?> </tbody> </table> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.