首页 > 代码库 > 随机图片大小在DIV中垂直居中对齐总结

随机图片大小在DIV中垂直居中对齐总结

老遇到这种样式 现在总结一下

<!DOCTYPE><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title><style>    *{margin:0;padding:0;line-height: 1;font-size: ‘宋体‘;padding:0;font-size: 1em;}    body{background-color: #000;}    #canvas{width: 900px;margin:50px auto;}    .box{width: 900px;height: 2000px;text-align: center;display: table-cell;background-color: #fff;*zoom:1;}    .box em{width: 0;height: 100%;display: inline-block;vertical-align: middle;}    .box img{display:inline-block;vertical-align: middle;}</style></head><body><div id="canvas">    <div class="box"><em></em><img src="http://e.hiphotos.baidu.com/image/pic/item/8d5494eef01f3a29a1dde8c79b25bc315c607ca5.jpg" alt="" /></div></div></body></html>