边距:汽车未居中 [英] margin: auto is not centering

查看:62
本文介绍了边距:汽车未居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网站上的以下样式: http://6.470.scripts.mit。 edu / css_exercises / exercise4.html

<style type="text/css">
  #sponsors {
         margin:auto;
         margin-top:50px;
         overflow: hidden;
         width: auto;
         display: inline-block;
  }
  div.image img {
         margin: 3px;
         border: 1px solid #ffffff;
  }
  div.image a:hover img {
        border: 1px solid;
  }
</style>
</head>
<body>
 <h1>Sponsors of 6.470</h1>
 <div id="sponsors">
   <div class="image"><a href=""><img src="images/appian.png" width="150" height="85"></a></div>
   <div class="image"><a href=""><img src="images/dropbox.png" width="150px" height="85px"></a></div>
   <div class="image"><a href=""><img src="images/facebook.png" width="150px" height="85px"></a></div>
   <div class="image"><a href=""><img src="images/nextjump.png" width="150px" height="85px"></a></div>
   <div class="image"><a href=""><img src="images/palantir.png" width="150px" height="85px"></a></div>
   <div class="image"><a href=""><img src="images/quora.png" width="150px" height="85px"></a></div>
   <div class="image"><a href=""><img src="images/tripadvisor.png" width="150px" height="85px"></a></div>
   <div class="image"><a href=""><img src="images/vecna.png" width="150px" height="85px"></a></div>
  </div>
</body>

如果 width:auto #sponsors ,则即使 margin:auto ,div 也不居中对齐code>被使用。

if the width: auto is removed from #sponsors then the div#sponsors is not center aligned even though margin: auto is used.

类似地,如果用 margin:auto <代替 text-align:center / code>以上的正文样式,则< h1> 不会居中对齐,这很荒谬;

Similarly if instead of text-align: center is replaced by margin: auto in body style above, then the <h1> will not be center aligned which is preposterous;

因为我已经使用 margin:auto 很多次了,所以它能够使内容居中而没有任何问题。因此,请帮助我,对此我将不胜感激。

because I have used margin: auto a lot of times and it was able to center the content without any issue. So hence help me and I will appreciate this a lot.

PS:除了使用 doctype 外,我还使用了firefox标记,它仍然不能与 margin:auto 居中。

PS: I used firefox and besides use the doctype tag it is still not able to center with margin: auto.

推荐答案

#sponsors ID上定义宽度边距

像这样

#sponsors{
margin:0 auto; // left margin is auto, right margin is auto , top and bottom margin is 0 set
width:1000px; // define your width according to your design 
}

有关 保证金自动

More about margin auto

这篇关于边距:汽车未居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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