<div style="width: 200px; position:relative; top: 200px; background: silver;"> <div class="slidesWrap" style="height:200px"> <div style="height:300px; width:100%; background: pink;">content</div> <div style="height:30px; width:100%; background: green;">content</div> </div> </div>
.slidesWrap { display: flex; align-items: center; overflow: auto; } .slide { overflow: auto; flex: 1; max-height:100%; }
结果:ide
左侧区域的content不见了。并且滚动也不会出现。
这是由于overflow:scroll 只会对下方或右侧超出的部分滚动 ,对左侧和上方无效(左侧能够尝试float: right设置超出。也是横向无滚动)flex
1.中间再包一层
2.max-height:100%;spa
实例:code
<div style="width: 200px; position:relative; top: 200px; background: silver;"> <div class="slidesWrap" style="height:200px"> <div class="slide"> <div style="height:300px; width:100%; background: pink;">content</div> </div> <div class="slide"> <div style="height:30px; width:100%; background: green;">content</div> </div> </div> </div>
.slidesWrap { display: flex; flex-direction: row; align-items: flex-end; } .slide { overflow: auto; flex: 1; max-height:100%; }
结果:blog