【问题标题】:bootstrap carousel center image vertical and horizontal引导轮播中心图像垂直和水平
【发布时间】:2019-01-08 10:02:47
【问题描述】:

我有两个图像轮播,其中每个图像的大小不同。我试图让它们都在中间垂直对齐,以便看起来更干净。

我试过:边距,显示:块,垂直对齐:中间。没有人在轮播中心制作图像。

<div class="container">
  <div class="col-md-12 text-align-center">
    <h2 class="bold_font">FEATURED PARTNERS</h2><br>
  </div>
        <div class="row">
            <div class="col-xs-4">
              <a href="../cards/list-partners.php">
              <div class="hvrbox">
                <img src="img/_stock_mwc_partners.jpg" class="img-responsive hvrbox-layer_bottom">
                <div class=" hvrbox-mwc-orange hvrbox-layer_top hvrbox-layer_slideright">
                  <div class="hvrbox-text">
                    <h2>BROWSE<br>PARTNERS</h2>
                  </div>
                </div>
              </div>
              </a>
            </div>
            <div class="col-xs-8">
                <div id="imageCarousel" class="carousel slide" data-interval="2000" data-ride="carousel" data-pause="hover" data-wrap="true">
                    <div class="carousel-inner">
                        <div class="item active">
                            <div class="row">
                                <div class="col-md-6 img-center-vertical">
                                    <img src="img/uploads/merchant-12-GLOBAL ELITE DENTAL CLINIC.jpg" class="img-responsive">
                                </div>
                                <div class="col-md-6 img-center-vertical">
                                    <img src="img/uploads/merchant-17-Mimmo Logo.jpg" class="img-responsive">
                                </div>
                            </div>
                        </div>
                        <div class="item">
                            <div class="row">
                                <div class="col-md-6 img-center-vertical">
                                    <img src="img/uploads/merchant-18-LOGO CORE.png" class="img-responsive">
                                </div>
                                <div class="col-md-6 img-center-vertical">
                                    <img src="img/uploads/merchant-19-docnic_newlogo-3.png" class="img-responsive">
                                </div>
                            </div>
                        </div>

                    </div>

                    <a href="#imageCarousel" class="carousel-control left" data-slide="prev">
                        <span class="glyphicon glyphicon-chevron-left"></span>
                    </a>
                    <a href="#imageCarousel" class="carousel-control right" data-slide="next">
                        <span class="glyphicon glyphicon-chevron-right"></span>
                    </a>
                </div>

            </div>
        </div>
    </div>

【问题讨论】:

    标签: html css twitter-bootstrap


    【解决方案1】:

    我们可以使用显示表格和显示表格单元格来实现这一点。

    .item row{
      display:table;
    }
    
    .img-center-vertical{
      display:table-cell;
      vertical-align:middle;
      height:300px;
      float: inherit;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" >
    
    
    
    <div class="container">
      <div class="col-md-12 text-align-center">
        <h2 class="bold_font">FEATURED PARTNERS</h2><br>
      </div>
            <div class="row">
                <div class="col-xs-4">
                  <a href="../cards/list-partners.php">
                  <div class="hvrbox">
                    <img src="http://placehold.it/300/f44336/000000" class="img-responsive hvrbox-layer_bottom">
                    <div class=" hvrbox-mwc-orange hvrbox-layer_top hvrbox-layer_slideright">
                      <div class="hvrbox-text">
                        <h2>BROWSE<br>PARTNERS</h2>
                      </div>
                    </div>
                  </div>
                  </a>
                </div>
                <div class="col-xs-8">
                    <div id="imageCarousel" class="carousel slide" data-interval="false" data-ride="carousel" data-pause="hover" data-wrap="true">
                        <div class="carousel-inner">
                            <div class="item active">
                                <div class="row">
                                    <div class="col-md-6 img-center-vertical">
                                        <img src="http://placehold.it/300/f44336/000000" class="img-responsive">
                                    </div>
                                    <div class="col-md-6 img-center-vertical">
                                        <img src="http://placehold.it/200/f44336/000000" class="img-responsive">
                                    </div>
                                </div>
                            </div>
                            <div class="item">
                                <div class="row">
                                    <div class="col-md-6 img-center-vertical">
                                        <img src="http://placehold.it/300/f44336/000000" class="img-responsive">
                                    </div>
                                    <div class="col-md-6 img-center-vertical">
                                        <img src="http://placehold.it/200/f44336/000000" class="img-responsive">
                                    </div>
                                </div>
                            </div>
    
                        </div>
    
                        <a href="#imageCarousel" class="carousel-control left" data-slide="prev">
                            <span class="glyphicon glyphicon-chevron-left"></span>
                        </a>
                        <a href="#imageCarousel" class="carousel-control right" data-slide="next">
                            <span class="glyphicon glyphicon-chevron-right"></span>
                        </a>
                    </div>
    
                </div>
            </div>
        </div>

    查看codepen

    【讨论】:

    • 很高兴听到这个消息。 :)
    【解决方案2】:
    .img-center-vertical {
    display: inline-block;
    text-align: center;
    justify-content: center;
    

    }

    【讨论】:

      【解决方案3】:

      试试这个

      .img-center-vertical {
          display: flex;
          align-items: center;
          justify-content: center;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-06-23
        • 2018-08-06
        • 2015-12-07
        • 2016-07-15
        • 2017-09-19
        • 2011-07-25
        • 1970-01-01
        • 2016-08-01
        相关资源
        最近更新 更多