【发布时间】:2022-02-22 18:01:09
【问题描述】:
我知道有许多类似的帖子,但我无法将它们应用于我的问题。
我在引导网格的最后一行有一个表格:
<div class="container-fluid">
<!-- Here are some other rows with dynamically varying sizes -->
<div class="row">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Size (byte)</th>
<th>Loaded</th>
</tr>
</thead>
<tbody>
@foreach (var file in _filesToUpload)
{
<tr>
<td>@file.Name</td>
<td>@file.FileType</td>
<td>@file.FileSize</td>
<td>@file.Loaded.ToString()</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
对应的css如下所示:
.table {
color: white;
background-color: rgba(0, 0.941, 0, 0.5);
}
.table-responsive {
height: 40rem;
overflow: auto;
}
thead tr:nth-child(1) th {
background-color: black;
position: sticky;
top: 0;
z-index: 10;
}
整个事情都在 .page 容器和 main 容器中(这是 blazor 默认项目设置):
<div class="page">
<div class="sidebar">
<NavMenu />
</div>
<div class="main">
<div class="top-row px-4 auth">
<LoginDisplay />
</div>
<div class="content px-4">
@Body <!-- here the code from above gets inserted -->
</div>
</div>
</div>
最后,我为page 和main 类提供了以下css。
.page {
position: relative;
display: flex;
flex-direction: column;
height: 100vh;
overflow: auto;
background-color: transparent;
}
.main {
flex: 1;
background-image: url(../web/wallpaper.jpg);
background-repeat: no-repeat;
background-position: top 0 right 0;
background-size: cover;
background-attachment: fixed;
}
我想要的是背景固定到位,并且所有内容变得太大,都有一个滚动条。使用上面的代码,只要我处于全屏/全高清模式,它就可以正常工作。一旦浏览器调整大小,表格就会从页面底部“伸出”(整个页面有一个额外的滚动条,并且可以向下滚动到背景图像下方)。
解决方案必须是在table-responsive 类中使用动态高度,但我找不到正确的方法。
【问题讨论】:
标签: html css bootstrap-4 blazor