为什么margin:auto不工作? [英] Why margin:auto doesn't work?

查看:174
本文介绍了为什么margin:auto不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要定位我的元素,但当我使用

  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;
}

,您可以看到结果

有人可以帮助我吗?

  margin-left:auto; 
margin-right:auto;

不会影响元素宽度 display:inline



如果你想要它的工作,你应该给一个固定的宽度,并设置 display:block code> display:inline-block 。


I want to center my element but when I use

margin-left: auto;
margin-right: auto;

it doesn't work!

this is my html

<section id="t">
    <article class="tc">Hi</article>
    <article class="tc">Hi agian!</article>
</section>

and this is my 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;
}

and you can see the result here.

Can anybody help me?

解决方案

margin-left: auto;
margin-right: auto;

would not effect the element width display:inline.

If your want it works, you should give a fixed width, and set display:block or display:inline-block.

这篇关于为什么margin:auto不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆