图片水平、垂直居中与父元素的css方法

2019-04-15 13:19发布

<body> <div class="pic"><img src="https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1438475101,354016904&fm=58" alt="">div> <div class="pic"><img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2201558756,12364836&fm=111&gp=0.jpg" alt="">div>body>html><style>.pic { width: 120px;height: 120px;margin: 40px auto;border: 1px solid #ccc;text-align: center;padding: 5px;}.pic:before { content: "";display: inline-block;height: 100%;vertical-align: middle;width: 0;}.pic img { max-width: 120px; max-height: 120px;vertical-align: middle;}style>
源自:http://blog.csdn.net/fungleo/article/details/71521964