你如何轻松地水平居中使用CSS的<div>?
  我试图在页面上水平放置一个<div>块元素,并将其设置为最小宽度。  什么是最简单的方法来做到这一点?  我希望<div>元素与我的页面的其余部分内联。  我会试着画一个例子: 
page text page text page text page text
page text page text page text page text
               -------
               | div |
               -------
page text page text page text page text
page text page text page text page text
在非固定宽度 div的情况下(即,您不知道div将占用多少空间)。
#wrapper {
  background-color: green; /* for visualization purposes */
  text-align: center;
}
#yourdiv {
  background-color: red; /* for visualization purposes */
  display: inline-block;
}<div id="wrapper">    
    <div id="yourdiv">Your text</div>
</div>在大多数浏览器中,这将起作用:
div.centre {
  width: 200px;
  display: block;
  background-color: #eee;
  margin-left: auto;
  margin-right: auto;
}<div class="centre">Some Text</div>margin: 0 auto;
正如ck所说,所有浏览器都不支持min-width
链接地址: http://www.djcxy.com/p/29989.html上一篇: How do you easily horizontally center a <div> using CSS?
