i have a table that i made in html/css, i made the header of the table freeze by putting position: sticky and top: 0. this works, but the border that i have on the bottom of header does not stick, it scrolls with the content. How can i make the border on the header frozen like the header is? I would tell you what i have tried, but honestly i am still new to css and do not even know where to start debugging this. I did not find any solutions on online that worked for my issue at least. Please help me to solve this.
<html lang="en">
<head>
<link rel="stylesheet" href="index.css">
<link href="https://fonts.googleapis.com/icon?family=Material Icons" rel="stylesheet">
</head>
<body>
<div id="app-header">aplog</div>
<div id="page-header">
<div>Invoices</div>
<button>New Invoice</button>
</div>
<div id="contents">
<div id="searchbar">
<input type="search" placeholder="Search ....">
<div >tune</div>
<div >download</div>
</div>
<div id="table-wrapper">
<table>
<thead>
<tr>
<th>invoice#</th>
<th>vendor</th>
<th>date</th>
<th>po</th>
<th>amount</th>
</tr>
</thead>
<tbody id="tbody"></tbody>
</table>
</div>
</div>
<script src="index.js"></script>
</body>
</html>
* {
margin: 0;
padding: 0;
}
body {
width: 100vw;
height: 100vh;
user-select: none;
display: grid;
grid-template-rows: auto auto 1fr;
background-color: #E9E9E9;
}
#app-header {
padding: 1rem 1rem 1rem 1rem;
font-weight: bold;
background-color: #003469;
color: white;
}
#page-header {
padding: 1rem 1rem 1rem 1rem;
font-weight: bold;
font-size: 1.5rem;
display: flex;
justify-content: space-between;
}
button {
padding: .25rem .5rem .25rem .5rem;
}
#contents {
background-color: white;
margin: 0rem 1rem 1rem 1rem;
border-radius: 5px;
border: 1px solid lightgray;
display: grid;
grid-template-rows: auto 1fr;
overflow: hidden;
}
#searchbar {
padding: 1rem;
border-bottom: 1px solid lightgray;
}
#table-wrapper {
overflow-y: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
th {
background-color: #F5F5F5;
border-bottom: 1px solid lightgray;
}
th, td {
padding: 1rem 1rem 1rem 1rem;
}
input[type="search"] {
border: 0;
outline: 0;
width: 100%;
}
#searchbar {
display: grid;
grid-template-columns: 1fr auto auto;
gap: .5rem;
}
thead, th {
position: sticky;
top: 0;
}
td {
border-bottom: 1px solid lightgray;
}
#table-wrapper::-webkit-scrollbar {
width: 0;
}
tr:hover {
background-color: steelblue;
}
th, td {
text-align: left;
}
th:last-child, td:last-child {
text-align: right;
}
CodePudding user response:
You should change the value of border-collapse:
table {
border-collapse: separate;
}
CodePudding user response:
try position : fixed on header.