码迷,mamicode.com
首页 > 其他好文 > 详细

使用 padding-bottom 设置高度基于宽度的自适应

时间:2018-03-06 14:36:19      阅读:330      评论:0      收藏:0      [点我收藏+]

标签:otto   head   golden   adp   margin   pre   hot   css   伪类   

html 结构

<div class=‘detail‘>
<div class="person-pic-wrap">
<img :src=‘studentDetailDto.headPhoto‘>
</div>
</div>

detail 弹性盒子,宽度100%

person-pic-wrap 30%宽度
img宽度高度100%

css代码
方法1
.detail{
width: 100%;
height:120px;
position: absolute;
display: flex;
justify-content: space-around;
bottom: 0;
background: darkgoldenrod;
}
.person-pic-wrap{
width: 30%;
padding-bottom: 30%;
}
.person-pic-wrap>img{
width: 100%;
}

方法2 使用伪类
.person-pic-wrap{
width: 30%;
/*position: relative;*/
}
.person-pic-wrap:after{
content: ‘‘;
display: block;
margin-top: 100%;
}
.person-pic-wrap>img{
width: 100%;
 position: absolute;
}





使用 padding-bottom 设置高度基于宽度的自适应

标签:otto   head   golden   adp   margin   pre   hot   css   伪类   

原文地址:https://www.cnblogs.com/yangmengsheng/p/8514005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!