【发布时间】:2021-06-12 03:35:57
【问题描述】:
我正在使用 react-table 和样式化的组件,并试图使 tbody 可滚动并带有粘性头。我尝试为父容器设置高度,然后将 tbody overflow-y 设置为 auto,但是这种方法不起作用。我做错了什么?
const TableContainerOuter = styled.div`
width: 100%;
height: 100%;
overflow-y: hidden;
padding-bottom: 21px;
`;
const TableContainer = styled.div`
width: 100%;
height: 300px;
min-width: 900px;
`;
const StyledTable = styled.table`
width: 100%;
position: relative;
height: 30px;
border-spacing: 0px;
th {
position: sticky;
top: 0;
left: 0;
background: #f3f4f5;
font-size: 9px;
font-weight: 500;
line-height: 230%;
letter-spacing: 0.05em;
color: ${(props) => props.theme.pbDarker};
text-transform: uppercase;
text-align: left;
padding: 6px 0px;
user-select: none;
&:first-child {
border-top-left-radius: 6px;
border-bottom-left-radius: 6px;
padding-left: 22px;
}
&:last-child {
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
}
}
tbody {
overflow-y: scroll;
height: 100px;
}
td {
padding: 16px 0px;
border-style: solid;
border-width: 0px;
font-size: 12px;
font-weight: 400;
border-bottom-width: 1px;
border-color: ${(props) => props.theme.pbFaded1};
min-width: 95px;
:first-of-type {
padding-left: 22px;
}
}
`;
【问题讨论】:
标签: css reactjs html-table react-table