如何水平居中<div>块元素?</div>

时间:2010-09-10 20:17:05

标签: html

我正在尝试水平居中块元素。我怎么能做到这一点?

  <div class="content2">
   <div class="middle-content">
    <ul>


     <li>
      <div class="container">
       <div class="container-head">
        <div class="empty"></div>
       </div>
       <div class="content">
        <!--Place holder for member count-->
        <?php displayMemberCount(); ?>
        <!--End of Place holder for member count-->
        <div class="people-online">
         <p><strong>Paltalk</strong> makes it easy to connect with people that share your interests. <a href="http://www.paltalk.com/people/webapp/index.wmt">Browse all profiles</a></p>
         <?php members(); ?>
        </div>
        <!-- end people-online -->
       </div>
       <!-- end content -->
      </div>
      <!-- end container -->
     </li>

     <li class="last">
      <div class="container">
       <div class="container-head">
        <div class="empty"></div>
       </div>
       <div class="content">
        <!--Place holder for member count-->
        <?php displayRoomCount(); ?>
        <!--End of Place holder for member count-->
        <div class="groups-online">              
         <?php rooms(); ?>
        </div>
        <!-- end groups-online -->
       </div>
       <!-- end content -->
      </div>
      <!-- end container -->
     </li>
    </ul>
   </div>
   <!-- end middle-content -->
  </div>
  <!-- end content2 -->
 </div>
 <!-- end content -->

3 个答案:

答案 0 :(得分:6)

<div style="margin: 0 auto;">Some content</div>

答案 1 :(得分:5)

div {
    margin-left: auto;
    margin-right: auto;
    width: 100px;
}

答案 2 :(得分:4)

给他们一个宽度并在你的css中使用margin: 0px auto;