为什么margin:auto不工作? [英] Why margin:auto doesn't work?
问题描述
我想要定位我的元素,但当我使用
margin-left:auto;
margin-right:auto;
它不起作用!
这是我的html
< section id =t>
< article class =tc> Hi< / article>
< article class =tc> Hi agian!< / article>
< / section>
这是我的css:
#t {
margin-left:auto;
margin-right:auto;
margin-top:10px;
}
.tc {
margin-left:auto;
margin-right:auto;
width:600px;
display:inline;
border-style:solid;
border-width:1px;
}
,您可以看到结果 有人可以帮助我吗? 不会影响元素宽度 如果你想要它的工作,你应该给一个固定的宽度,并设置 I want to center my element but when I use it doesn't work! this is my html and this is my css: and you can see the result here. Can anybody help me? would not effect the element width If your want it works, you should give a fixed width, and set 这篇关于为什么margin:auto不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
margin-left:auto;
margin-right:auto;
display:inline
。
display:block
code> display:inline-block 。margin-left: auto;
margin-right: auto;
<section id="t">
<article class="tc">Hi</article>
<article class="tc">Hi agian!</article>
</section>
#t {
margin-left: auto;
margin-right: auto;
margin-top:10px;
}
.tc {
margin-left: auto;
margin-right: auto;
width: 600px;
display: inline;
border-style: solid;
border-width:1px;
}
margin-left: auto;
margin-right: auto;
display:inline
.display:block
or display:inline-block
.