gpt4 book ai didi

html - CSS显示:table-cell,设置高度和溢出:hidden,不起作用?

转载 作者:行者123 更新时间:2023-11-28 16:08:21 25 4
gpt4 key购买 nike

如果子元素的内容太大,我想剪掉一个元素,但它在 display:table-cell 元素中不起作用。这是 JsFiddle 上的示例:

JSFiddle

.table{
display: table;
table-layout: fixed;
width: 100%;
height:200px;
}
.cell{
display: table-cell;
vertical-align: top;
position: relative;
height:200px;
overflow:hidden;
}
.container{
height:100%;
background-color:red;
}
.container img{
display:block;
}
<div class="table">
<div class="cell">
<div class="container">
<img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
<img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
<img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
</div>
</div>

有人请告诉我哪里错了吗?谢谢!

最佳答案

为了让它工作,我们必须对表格使用 position:relative,对表格单元格元素使用 position:absolute。同样在您的代码中,我删除了 container's height: 100% 这是没有用的。这是预览和 fiddle .

.table{
display: table;
table-layout: fixed;
width: 100%;
height:200px;
position: relative;
}
.cell{
display: table-cell;
vertical-align: top;
position: absolute;
height:200px;
width: 100%;
overflow-y:scroll;
overflow-x: hidden;
}
.container{
background-color:red;
}
.container img{
display:block;
}
<div class="table">
<div class="cell">
<div class="container">
<img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
<img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
<img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
</div>
</div>

关于html - CSS显示:table-cell,设置高度和溢出:hidden,不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38758263/

25 4 0