img标签在div中水平垂直居中
通过设置img为绝对定位,处于垂直和水平50%,然后平移自身宽高的50%
div{ position: relative; width: 400px; height: 400px; border: 1px solid #000; } img{ position: absolute; top:50%; left:50%; transform: translate(-50%,-50%); }
div{ position: relative; width: 400px; height: 400px; border: 1px solid #000; } img{ position: absolute; top:50%; left:50%; transform: translate(-50%,-50%); }