Ich habe ein einfaches 3-teiliges Layout (Header/Sidebar/Inhalt) mit CSS-Gitter. In meinem Inhalt habe ich einen Tisch.Scrollable tbody im Raster Layout
Ich möchte die Tabelle füllen den verbleibenden Platz in der div.content
und haben eine tbody
mit einer eigenen Bildlaufleiste.
Jede Kombination von overflow-y: scroll;
und position: relative
mit verschiedenen Breiten/Höhen führen entweder die div.content
die Scrollbar bekommen, oder die <table>
überfüllt (Beispiel siehe - auch auf jsbin).
Wie kann ich diese Tabellen <tbody>
die Bildlaufleiste erhalten, und die Tabelle selbst durch den Inhalt div ohne Überlauf begrenzt haben?
html, body {
margin: 0;
height: 100%;
}
main {
display: grid;
grid-template-areas: 'header header' 'sidebar content';
grid-template-rows: 100px 1fr;
grid-template-columns: 200px 1fr;
width: 100%;
height: 100%;
}
header {
background-color: #CCC;
grid-area: header;
padding: 20px;
}
aside {
background-color: #EEE;
grid-area: sidebar;
padding: 10px;
}
aside img {
width: 100%;
mix-blend-mode: darken;
}
div.content {
position: relative;
display: flex;
flex-direction: column;
grid-area: content;
min-height: 0;
min-width: 0;
padding: 10px;
max-height: 100%;
border-bottom: 2px solid black;
overflow-y: scroll;
}
table {
margin: 10px;
width: 100%;
}
thead {
text-align: left;
}
tbody {
height: 100%;
overflow-y: scroll;
}
.code {
font: 12px Courier;
color: blue;
}
<main>
<header>
<h2>Really rad app title</h2>
</header>
<aside>
<img src="https://thumb7.shutterstock.com/display_pic_with_logo/436114/423846025/stock-vector-example-stamp-423846025.jpg" />
<span>Some Contextual Informations and other such sidebar-y things<span>
</aside>
<div class="content">
<h3>Some Stuffs</h3>
<div>
Why does this <span class="code"><tbody></span> ignore my <span class="code">overflow-y: scroll;</span>?
<br /><br />
I want <span class="code">div.content</span> to act as a portal/window, with everything around it remaining fixed; but I want the table to stop before the bottom of this window and have a scrollable body (instead of scrolling this text offscreen).
</div>
<table>
<thead><tr><th>One</th><th>Two</th><th>Three</th></tr></thead>
<tbody>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Some content</td><td>Some Content</td><td>Some Content</td></tr>
<tr><td>Too much content</td><td>Too much content</td><td>Too much content</td></tr>
<tr><td>Too much content</td><td>Too much content</td><td>Too much content</td></tr>
<tr><td>Too much content</td><td>Too much content</td><td>Too much content</td></tr>
<tr><td>Too much content</td><td>Too much content</td><td>Too much content</td></tr>
<tr><td>Too much content</td><td>Too much content</td><td>Too much content</td></tr>
<tr><td>Too much content</td><td>Too much content</td><td>Too much content</td></tr>
<tr><td>Too much content</td><td>Too much content</td><td>Too much content</td></tr>
<tr><td>Too much content</td><td>Too much content</td><td>Too much content</td></tr>
</tbody>
</table>
</div>
</main>
Brilliant! Vielen Dank.Allerdings wollte ich das '
' scrollen (dh: halte die Header statisch), also habe ich es 'overflow-y: hidden;' gemacht und lass das 'overflow-y: scroll;' auf dem tbody übernehmen. Aber danke für die Wrapper-Idee ... Mann HTML/CSS kann manchmal unintuitiv sein. –@AlexMcMillan yeah css/html verhält sich nicht so, wie Sie es gerne hätten. Sie können auch keine feste Kopfzeile mit dem Gehörlosen '
Wenn Sie nur drei Spalten verwenden, verwenden Sie stattdessen Spalten? Sie könnten wahrscheinlich einen festen Header mit scrollbaren Körper leichter so manipulieren. https://www.w3schools.com/css/css3_multiple_columns.asp –
Sie haben einen anderen Wert der Höhe des tbody wie
zu geben und auch Thead, tbody, tr und td anzuzeigen Zeigen Sie sie mit der Eigenschaft blok an: .table-fixed thead, .table-fixed tbody, .table-fixed tr, .table-fixed td, .table-fixed { display: block; }
Verwenden Bootstrap, die Sie alow eine einfache und effektive Seite zu machen, es ist einfach zu handhaben:
hier ist ein kompletter ex, die für mich funktioniert:
dies ist der html Datei:
und dies ist die CSS-Datei:
Quelle
2017-09-11 23:24:29
Aber, Die Höhe der Tabelle ändert sich basierend auf der Bildschirmgröße des Benutzers. –
Wenn Sie das wollen, so wird Bootstrap es für Sie tun, wenn Sie ein festes festes Eigentum der Tabelle hinzufügen möchten –
Verwandte Themen