Image 在div中居中定位图像

Image 在div中居中定位图像,image,css,alignment,anchor,Image,Css,Alignment,Anchor,我有一个在锚元素中的图像 我希望图像的锚点在父div中垂直和水平居中 例如: <div class="wrapper"> <a href="#" class="anchor"> <img src="http://bit.ly/1mFH8AW"></img> </a> </div> .wrapper { background: black; width: 500px; h

我有一个在锚元素中的图像

我希望图像的锚点在父div中垂直和水平居中

例如:

<div class="wrapper">
    <a href="#" class="anchor">
        <img src="http://bit.ly/1mFH8AW"></img>
    </a>
</div>
.wrapper {
    background: black;
    width: 500px;
    height: 500px;
}
.anchor {
}
.anchor > img {
    height: 100px;
    width: 100px;
}

.包装纸{
背景:黑色;
宽度:500px;
高度:500px;
}
.主播{
}
.anchor>img{
高度:100px;
宽度:100px;
}
结果:


位置:relative
添加到包装器,然后将图像的CSS更改为:

.anchor > img {
    height: 100px;
    width: 100px;
    position:absolute;
    margin:auto;
    top:0;right:0;bottom:0;left:0;
}

为什么边距自动而非边距0自动,因为
0自动
只会将其水平居中,OP要求垂直和水平两种方式。自动同时处理所有四个。