Hey there! I'm working on a dynamic table that I populate using data from my API. However, I'm facing an issue where I want the table to maintain a minimum height when there are only a few results, but I can't seem to make it work.
I attempted to set the min-height to calc(100% - 60px) in my CSS to ensure that the table always has that minimum height, but it doesn't work as expected when the number of entries is low:
https://i.sstatic.net/XIivT.png
CSS in JavaScript:
/* Styles */
export const DepartamentMain=styled("div")` min-height: calc(100% - 60px) !important;
width: 100%;
padding: 0 20px;
`;
export const TableContent=styled("div")` box-shadow: 0 0 0 1px rgb(63 63 68 / 5%),
0 1px 2px 0 rgb(63 63 68 / 15%);
border-radius: 4px;
height: 100%;
`;
export const ResponsiveTable=styled("table")` width: 100%;
margin: 0;
padding: 0;
border-collapse: collapse;
border-spacing: 0;
.paddingCheckbox {
width: 48px;
padding: 0 0 0 4px !important;
color: #263238;
font-weight: 500;
line-height: 1.5rem;
font-size: 0.875rem;
text-align: left;
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
}
tr {
color: inherit;
display: table-row;
outline: 0;
vertical-align: middle;
border-spacing: 0;
border-collapse: collapse;
}
.tr-head {
th {
border-bottom: 1px solid rgba(224, 224, 224, 1);
letter-spacing: 0.01071em;
vertical-align: inherit;
display: table-cell;
padding: 16px;
font-size: 0.875rem;
text-align: left;
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
color: #263238;
font-weight: 500;
line-height: 1.5rem;
}
}
.root {
padding: 9px;
flex: 0 0 auto;
overflow: visible;
font-size: 1.5rem;
text-align: center;
transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
border-radius: 50%;
display: inline-flex;
border: 0;
cursor: pointer;
margin: 0;
position: relative;
align-items: center;
user-select: none;
justify-content: center;
vertical-align: middle;
background-color: transparent;
}
thead {
visibility: visible;
background: #fff;
}
tbody {
display: table-row-group;
vertical-align: middle;
border-color: inherit;
border-collapse: collapse;
border-spacing: 0;
visibility: visible;
background: #fff;
td {
display: table-cell;
padding: 16px;
font-size: 0.875rem;
text-align: left;
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
font-weight: 400;
line-height: 1.43;
border-bottom: 1px solid rgba(224, 224, 224, 1);
letter-spacing: 0.01071em;
vertical-align: inherit;
}
}
<div style={{ height: "100%", padding: 60 }} className="App">
<DepartamentMain>
<TableContent>
<ResponsiveTable>
<thead>
<tr className="tr-head">
<th className="paddingCheckbox">
<span className="root">
<input name="select-all" value="ALL" />
</span>
</th>
<th>title 1</th>
<th>tittle 2</th>
<th>tittle 3</th>
<th>tittle 4</th>
<th>tittle 5</th>
</tr>
</thead>
<tbody>{renderDataList()}</tbody>
</ResponsiveTable>
</TableContent>
</DepartamentMain>
</div>