css如何实现一个自适应容器

2020-07-11 21:19:01易采站长站整理

css代码:

.box{    width: 100%;}.text{    overflow: hidden;    height: 0;    padding-bottom: 51.5%;}.box .text img{    width: 100%;}

这里 .text 的 padding-bottom: 51.5%; 也是按照第一个方法,用图片原始尺寸的宽高比计算出来的,需要注意,这里将 .text 设置 height: 0; 会出现高度比实际高的问题,因此为了避免这个情况,就需要设置 height: 0; 。

相关视频教程推荐:css视频教程