Вот решение с grid
:
body {
display: grid;
grid-template-rows: auto 1fr auto;
/* you may want to set `height` of `html` and `body` to `100%` instead of this
https://developers.google.com/web/updates/2016/12/url-bar-resizing */
height: 100vh;
}
.header > .w3-col {
width: 50%;
}
.table-container {
min-height: 0;
}
.table-container > .w3-col, .table-container .w3-container {
height: 100%;
}
.table-container .w3-container {
overflow-y: scroll;
}
#dataTable {
border: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Responsive Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body class="w3-light-grey">
<div class="w3-row-padding header">
<div class="w3-col"><p>A value</p></div>
<div class="w3-col"><p>Another value</p></div>
</div>
<div class="w3-row-padding table-container">
<div class="w3-col">
<div class="w3-container w3-padding-8">
<h5>Records</h5>
<table id="dataTable" class="w3-table-all w3-card-4">
<tr><th>Field1</th><th>Field2</th><th>Field3</th><th>Field4</th></tr>
<tr><td>First Value</td><td>First Value</td><td>First Value</td><td>First Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Last Value</td><td>Last Value</td><td>Last Value</td><td>Last Value</td></tr>
</table>
</div>
</div>
</div>
<div class="w3-row-padding footer">
<p>Footer</p>
</div>
</body>
</html>
Я не очень разбираюсь в grid
, поэтому, если вы собираетесь использовать это решение, я бы посоветовал вам изучить grid
там жеможет быть лучше / яснее.
Вот решение Flexbox:
body {
display: flex;
flex-direction: column;
/* you may want to set `height` of `html` and `body` to `100%` instead of this
https://developers.google.com/web/updates/2016/12/url-bar-resizing */
height: 100vh;
}
.header, .footer {
flex: none;
}
.header > .w3-col {
width: 50%;
}
.table-container {
flex: auto;
min-height: 0;
}
.table-container > .w3-col, .table-container .w3-container {
height: 100%;
}
.table-container .w3-container {
overflow-y: scroll;
}
#dataTable {
border: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Responsive Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body class="w3-light-grey">
<div class="w3-row-padding header">
<div class="w3-col"><p>A value</p></div>
<div class="w3-col"><p>Another value</p></div>
</div>
<div class="w3-row-padding table-container">
<div class="w3-col">
<div class="w3-container w3-padding-8">
<h5>Records</h5>
<table id="dataTable" class="w3-table-all w3-card-4">
<tr><th>Field1</th><th>Field2</th><th>Field3</th><th>Field4</th></tr>
<tr><td>First Value</td><td>First Value</td><td>First Value</td><td>First Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Last Value</td><td>Last Value</td><td>Last Value</td><td>Last Value</td></tr>
</table>
</div>
</div>
</div>
<div class="w3-row-padding footer">
<p>Footer</p>
</div>
</body>
</html>
Вот хакерский способ с calc
:
body {
/* you may want to set `height` of `html` and `body` to `100%` instead of this
https://developers.google.com/web/updates/2016/12/url-bar-resizing */
height: 100vh;
}
.header > .w3-col {
width: 50%;
}
.table-container {
/* values taken from browser's inspector */
--header-height: 52.5px;
--footer-height: 52.5px;
height: calc(100% - var(--header-height) - var(--footer-height));
}
.table-container > .w3-col, .table-container .w3-container {
height: 100%;
}
.table-container .w3-container {
overflow-y: scroll;
}
#dataTable {
border: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Responsive Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body class="w3-light-grey">
<div class="w3-row-padding header">
<div class="w3-col"><p>A value</p></div>
<div class="w3-col"><p>Another value</p></div>
</div>
<div class="w3-row-padding table-container">
<div class="w3-col">
<div class="w3-container w3-padding-8">
<h5>Records</h5>
<table id="dataTable" class="w3-table-all w3-card-4">
<tr><th>Field1</th><th>Field2</th><th>Field3</th><th>Field4</th></tr>
<tr><td>First Value</td><td>First Value</td><td>First Value</td><td>First Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Value</td><td>Value</td><td>Value</td><td>Value</td></tr>
<tr><td>Last Value</td><td>Last Value</td><td>Last Value</td><td>Last Value</td></tr>
</table>
</div>
</div>
</div>
<div class="w3-row-padding footer">
<p>Footer</p>
</div>
</body>
</html>