我在我的页面中使用jQuery动画添加了一些CSS属性,我不明白为什么margin: auto它不起作用.
HTML代码(由jQuery添加样式属性):
<body style="overflow: hidden;">
<div id="tuto_wamp" style="width: 7680px; height: 923px; ">
<!-- Step 1 -->
<div style="height: 549px; width: 1280px; margin-top: 0px; margin-left: 0px; position: absolute; overflow-y: hidden; overflow-x: hidden; ">
<div class="content_tuto">
<img src="images/install1.png" alt="">
</div>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
我的CSS代码:
#tuto_wamp
{
background: #3a393c;
width: 100%;
}
.content_tuto
{
width: 100%;
margin: auto;
display: block;
}
Run Code Online (Sandbox Code Playgroud)
我不知道哪个属性会阻止margin: auto图像居中.
谢谢.
小智 5
我知道这是一个老帖子,但想分享我是如何解决同样的问题的.
我的图片是float:left从父类继承的.通过设置float:none我能够margin:0 auto正常工作.希望它可能在将来帮助某人.
添加text-align:center;到.content_tuto,它将居中
请注意,您有宽度style="width: 7680px; ...和style=".. width: 1280px; ...,因此当您居中时,您将以该宽度居中。