【问题标题】:Centering elements with bootstrap使用引导程序居中元素
【发布时间】:2014-05-13 05:21:22
【问题描述】:

我一直在尝试和搜索如何使用 Bootstrap 使元素居中,但似乎找不到方法。第一行容器中心正好使用center block 类。

我发现 HERE 在这种情况下将 .navbar-nav>li 更改为 float:none; 可以解决问题,但对我来说它只是垂直堆叠图标。

提前致谢。

<div class="container" style="height: 30px;"></div>
  <div class="row">
    <div class="col-md-4" style="">
       <a class="brand" href="index.php"> <img style="width: 57%;" class="center-block" src="img/xelha_logo.png" /></a>
    </div>
    <div class="col-md-4" style="background-color:blue;"> <!-- THIS ONE -->
        <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/facebook_logo.png" /></a>
        <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/twitter_logo.png" /></a>
        <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/youtube_logo.png" /></a>
        <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/tripadvisor_logo.png" /></a>
        <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/faq_logo.png" /></a>
        <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/mexicanflag.png" /></a>
    </div>
    <div class="col-md-4 center-block" style="background-color:green;"> <!-- AND THIS ONE -->
        <!-- Single button -->
        <div class="btn-group" >
          <button type="button" class="btn btn-default btn-lg dropdown-toggle center-block" data-toggle="dropdown">
            Customer Service <span class="caret"></span>
          </button>
          <ul class="dropdown-menu" role="menu">
            <li><a href="#">Canc&uacute;n: 998 2 51 65 60</a></li>
            <li><a href="#">Playa del Carmen: 984 1 47 65 60</a></li>
            <li><a href="#">M&eacute;xico: 01 800 21 28 951</a></li>
            <li><a href="#">USA-CAN: 188 892 27 381</a></li>
            <li><a href="#">Argentina: 0 800 666 15 26</a></li>
            <li><a href="#">Colombia: 01 800 931 67 45</a></li>
          </ul>
        </div>
    </div>
</div>

【问题讨论】:

    标签: html css twitter-bootstrap


    【解决方案1】:

    将您的代码更改为此并尝试:-

    <div class="container" >
    
    
    <div class="row">
    <div class="col-md-3">
    
    </div>
    <div class="col-md-2" >
    <a class="brand" href="index.php"> <img style="width: 57%;" src="img/xelha_logo.png" /></a>
    </div>
     <div class="col-md-2" style="background-color:blue;">
    <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/facebook_logo.png" /></a>
            <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/twitter_logo.png" /></a>
            <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/youtube_logo.png" /></a>
            <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/tripadvisor_logo.png" /></a>
            <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/faq_logo.png" /></a>
            <a class="brand" href="#"> <img style="width: 10%;" class="" src="img/social/mexicanflag.png" /></a>
    </div>
    
    
    <div class="col-md-2" style="background-color:green;">
    
          <div class="btn-group" >
              <button type="button" class="btn btn-default btn-lg dropdown-toggle center-block" data-toggle="dropdown">
                Customer Service <span class="caret"></span>
              </button>
              <ul class="dropdown-menu" role="menu">
                <li><a href="#">Canc&uacute;n: 998 2 51 65 60</a></li>
                <li><a href="#">Playa del Carmen: 984 1 47 65 60</a></li>
                <li><a href="#">M&eacute;xico: 01 800 21 28 951</a></li>
                <li><a href="#">USA-CAN: 188 892 27 381</a></li>
                <li><a href="#">Argentina: 0 800 666 15 26</a></li>
                <li><a href="#">Colombia: 01 800 931 67 45</a></li>
              </ul>
            </div>
    </div>
    <div class="col-md-3" >
    </div>
    </div>
    

    【讨论】:

    • 不,它只是将 3 个元素堆叠在一起。谢谢,我只需要将元素放在 col-md 中而不是整个文档的中心。
    • 哦,好吧,我以为您要求将每个元素分别居中。我已经更新了代码,现在试试这个。如果您觉得元素有点远,请更改 col-md-x 值中的 x 以正确划分屏幕。
    猜你喜欢
    • 1970-01-01
    • 2012-12-08
    • 2018-02-13
    • 1970-01-01
    • 2014-07-20
    • 2020-02-02
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    相关资源
    最近更新 更多