边距不适用于图像上的自动标记

Margins wont work with auto tag on image

正在尝试使图像居中。

使用 margin-left: auto;margin-right: auto; 标签不起作用。

下面是我的实现 我做错了什么/我需要添加什么

<style>
.fix{
    position:fixed;
    bottom:0px;
    width: 30%;
    margin-left: auto;
    margin-right: auto;
 }
</style>

<img src="DigitalBannerwithX.png" width="40%" height="auto" class="fix" onclick="this.style.display = 'none'" /> 

如果您使用 position: fixed;,您应该使用相应的 leftright 将其定位在中心位置(边距也可以,但每个都应该是加起来的百分比100% 宽度)。 http://codepen.io/anon/pen/dGjybG

你可以试试这个:

                  .fix{
position:fixed;
bottom:0px;
width: 30%;
margin-left:50%;
margin-right: 50%;
background-color:red;

}

DEMO HERE