我有一个可变宽度和高度的盒子。在我的示例中,我想将图片居中放置在盒子的中间。仅使用 CSS 解决此问题的最佳方法是什么?如果不需要,我宁愿不使用任何 JavaScript。
示例:http ://codepen.io/wesbos/pen/Ehour
我的 HTML:
<div class="box">
<img src="http://placekitten.com/200/200">
</div>
我的 CSS:
.box {
width:400px;
height:400px;
border:1px solid red;
text-align:center;
}