CSS display:table-单元格,设置高度和overflow:hidden,不起作用?

CSS display:table-cell, set height and overflow:hidden, doesn't work?

如果子元素的内容太大,我想剪掉一个元素,但它在 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>

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

更改您的 css 显示类型。

.table{
    display:block;
    width: 100%;
    height:200px;
}
.cell{
  display:block;
  vertical-align: top;
  position: relative;
  height:200px;
  overflow:hidden;
}
.container{
  height:100%;
  background-color:red;
}
.container img{
  display:block;
}

fiddle here

为了让它工作,我们必须对 table 使用 position:relative,对 table 单元格项目使用 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>