1
there is a way to make position: sticky
and overflow-x: auto
work together, without setting values of height
?
In that structure I set overflow-x: auto
in my class .scroll
, mine position: sticky
tag th
but when removing the overflow
the same works normally. I researched on and found that only work together with value of height
arrow.
Is there any other way to make the two properties work together? If yes only with css is possible? or do I need help with javascript? I’m using Angular7, if you need javascript, it’s possible without Jquery?
table {
min-width: 250px;
border-collapse: separate;
border-spacing: 0;
margin-right: 5px;
}
thead th {
position: sticky;
top: 0;
background-color: #c3ac6c;
}
th {
border-top: 1px solid;
border-bottom: 1px solid;
border-right: 1px solid;
text-align: center;
padding: 4.5px;
}
tbody tr:nth-child(even) {
background: #efefef;
overflow: hidden;
}
tbody tr:nth-child(even):hover {
background-color: #ffff99;
}
td {
border-bottom: 1px solid;
border-right: 1px solid;
padding: 4.5px;
text-align: center;
}
tr{
min-height: 25px;
}
th:first-child,
td:first-child {
border-left: 1px solid;
}
tr:hover {
background-color: #ffff99;
}
.fixed{
position: sticky;
left: 0;
padding: 0 5px 0 5px;
background-color: #fafafa;
z-index: 3;
width: 100%
}
.scroll {
display: flex;
justify-content: space-between;
width: 800px;
overflow-x: auto;
}
<div class="scroll">
<div class="fixed">
<table>
<thead>
<tr>
<th>1</th>
<th>2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td> <td>2</td>
</tr>
<tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr>
<tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr>
</tbody>
</table>
</div>
<table>
<thead>
<tr>
<th>1</th>
<th>2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td> <td>2</td>
</tr>
<tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr>
<tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>1</th>
<th>2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td> <td>2</td>
</tr>
<tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr>
<tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr>
</tbody>
</table>
<table >
<thead>
<tr>
<th>1</th>
<th>2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td> <td>2</td>
</tr>
<tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr>
<tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr> <tr>
<td>1</td> <td>2</td>
</tr>
</tbody>
</table>
</div>
Dude, I don’t get it, do you want this? https://imgur.com/JDxZvSW ? I was a little confused by what final result you expect...
– hugocsl
That’s right, but I can’t get to that result without setting
height
, I need my table to have the size of lines coming from the bank, with left table fixed, and headers fixed horizontally and vertically.– OtavioCapel