https://codepen.io/hatttfu/pen/ZEmVYwr
I have a table made using Grid Css. The problem is I can’t set border-radius to it because of overflow: auto, which I need.
What I’d like to achive (radiuses always on borders of table and stay there while scrolling):
thead, table, tbody, tr, th, td {
display: block
}
.table__row {
grid-template-columns: 74px 170px 170px 170px 170px 170px 170px 170px 170px 170px 170px;
display: grid;
grid-gap: 1px;
}
.table {
display: grid;
width: 1000px;
margin: 0 auto;
overflow: auto;
}
.table__head {
background-color: #EDEFF4;
padding: 20px 0;
height: 64px;
}
.table__body {
display: grid;
border-radius: 16px;
}
.table__cell {
padding: 12px 16px;
}
.table__body .table__cell {
background-color: #747C8C;
border-bottom: 1px solid #E2E4F6;
}
<table class="table">
<thead class="table__head">
<tr class="table__row">
<th class="table__cell table__cell_title">
Title
</th>
<th class="table__cell table__cell_title">
Title
</th>
<th class="table__cell table__cell_title">
Title
</th>
<th class="table__cell table__cell_title">
Title
</th>
<th class="table__cell table__cell_title">
Title
</th>
<th class="table__cell table__cell_title">
Title
</th>
<th class="table__cell table__cell_title">
Title
</th>
<th class="table__cell table__cell_title">
Title
</th>
<th class="table__cell table__cell_title">
Title
</th>
<th class="table__cell table__cell_title">
Title
</th>
<th class="table__cell table__cell_title">
Title
</th>
</tr>
</thead>
<tbody class="table__body">
<tr class="table__row">
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
</tr>
<tr class="table__row">
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
</tr>
<tr class="table__row">
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
</tr>
<tr class="table__row">
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
</tr>
<tr class="table__row">
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
<td class="table__cell">
Text
</td>
</tr>
</tbody>
</table>
I tried to set overflow for both body and header sections separately but in this case I need to make synchronized scroll because in this case they’ll scroll independently. Is there some another way to set border-radius to overflowing table?
2
Answers
Simple just apply overflow to the table body.
And you talk about scroll synchronized then there is one js plugin which will sync the both scroll at a same time (https://github.com/asvd/intence) have a look at it and hope you get solution for this!! 🙂
Since
@patel-harsh
‘s solution doesn’t fit the expected result, here’s a more complex CSS selector solution using:first-child
and:last-child
selectors