【发布时间】:2017-12-09 06:25:47
【问题描述】:
我在 div 中有一个表格,如下所示:
<div className="second-row-container">
<Table
rowsCount={this.state.myTableData.length}
rowHeight={50}
headerHeight={50}
width={9*150}
height={(this.state.myTableData.length+1)*50}>
<Column
header={<Cell>Delivery</Cell>}
cell={props => (
<Cell {...props}>
{this.state.myTableData[props.rowIndex].delivery}
</Cell>
)}
width={150}
/>
<Column
header={<Cell>Category</Cell>}
cell={props => (
<Cell {...props}>
{this.state.myTableData[props.rowIndex].age}
</Cell>
)}
width={150}
/>
<Column
header={<Cell>Language</Cell>}
cell={props => (
<Cell {...props}>
{this.state.myTableData[props.rowIndex].language}
</Cell>
)}
width={150}
/>
<Column
header={<Cell>Target market</Cell>}
cell={props => (
<Cell {...props}>
{this.state.myTableData[props.rowIndex].market}
</Cell>
)}
width={150}
/>
<Column
header={<Cell>Valid from</Cell>}
cell={props => (
<Cell {...props}>
{this.state.myTableData[props.rowIndex].valid_from}
</Cell>
)}
width={150}
/>
<Column
header={<Cell>Valid till</Cell>}
cell={props => (
<Cell {...props}>
{this.state.myTableData[props.rowIndex].valid_till}
</Cell>
)}
width={150}
/>
<Column
header={<Cell>Visibility</Cell>}
cell={props => (
<Cell {...props}>
{this.state.myTableData[props.rowIndex].visibility}
</Cell>
)}
width={150}
/>
<Column
header={<Cell></Cell>}
cell={props => (
<Cell {...props}>
</Cell>
)}
width={150}
/>
<Column
header={<Cell></Cell>}
cell={props => (
<Cell {...props}>
</Cell>
)}
width={150}
/>
</Table>
</div>
在 css 中我有:
.second-row-container{
height: 50vh;
background-color: lightgray;
padding: 0.5%;
width: 100%;
}
我认为通过将父宽度设置为 100%,当我缩小屏幕时表格总是会缩小,但事实并非如此。
如何使表格适合父 div 和小屏幕我希望隐藏第 3、4、5 和 6 列。我怎样才能做到这一点?
【问题讨论】:
-
width: 100%表示 div 占据了它自己的父容器宽度的 100%。width: auto将导致 div 拉伸/收缩以适应相对定位的孩子。但是,我认为这在您的情况下并不重要,您已经在子元素上设置了宽度和高度属性,并且我假设这些最终是在子元素上设置 CSS 宽度和高度,子元素的尺寸是不灵活的,并且无论屏幕尺寸如何都不会改变。您是否考虑过使用 CSS flex-box 来设置组件的样式以使其灵活?