:after伪类+content 让大小不固定图片垂直居中实例页面

代码:

CSS代码:
.pic_box{width:300px; height:300px; background-color:#beceeb; font-size:0; *font-size:200px; text-align:center;}
.pic_box img{vertical-align:middle;}
.pic_box:after{display:inline-block; width:0; height:100%; content:"center"; vertical-align:middle; overflow:hidden;}
                
HTML代码:
<div class="pic_box">
    <img src="//image.zhangxinxu.com/image/study/s/s256/mm1.jpg" />
</div>
                

效果:

分享到:0