2016-07-25 188 views
0

我需要在我的网页中并排显示图像和视频。下面的代码工作正常,除了对齐。水平中心对齐方式很好,因为视频和图像不是垂直居中的,我该如何解决它。Bootstrap col-md-6对齐垂直中心

<div class="container-fluid text-center" style="padding-top:100px;"> 
     <div class="row" > 
      <div class="col-md-6 " style="background-color:#000;min-height:700px;"> 
       <video id="video_id" width="100%" height="100%" controls="controls" align="middle" > 
        <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/ogg"> 
        Your browser does not support the video tag. 
       </video> 
      </div> 
      <div class="col-md-6 vcenter" style="background-color:#999;min-height:700px;"> 
       <img id ="detected_id" src="assets/images/src.jpg" width="100%" height="100%"> </img> 
      </div> 
     </div> 
    </div> 

我试过这里的解决方案vertical-align with Bootstrap 3但不工作。

+0

灿你创建一个小提琴? – ProEvilz

+0

你的图片尺寸是多少? –

+0

图片尺寸为900x600 – CodeDezk

回答

0

试试这个,我检查了你的代码,它在codepen.io上工作正常,但在jsFiddle它没有,所以我在头部添加了这个引导cdn,它在md (i.e. on desktop screen resolution)中工作正常。

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> 

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> 


<div class="container-fluid text-center" style="padding-top:100px;"> 

    <div class="row" > 

    <div class="col-md-6 " style="background-color:#000;min-height:700px;"> 
       <video id="video_id" width="100%" height="100%" controls="controls" align="middle" > 
        <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/ogg"> 
        Your browser does not support the video tag. 
       </video> 
      </div> 

    <div class="col-md-6 vcenter" style="background-color:#999;min-height:700px;"> 
       <img id ="detected_face_id" src="assets/images/mac.jpg" width="100%" height="100%"> 
      </div> 

    </div> 
0

display: table-cell;和父元素应该是display: table;可以显示元素垂直方向的中间的内容。

.row{ 
    display: table; 
} 
.vcenter{ 
    display: table-cell; 
    vertical-align: middle; 
} 

fiddle

0

当你没有说你也想支持Internet Explorer 8,你可以简单地使用其支持垂直中心没有任何麻烦一Flexbox的布局。 Flexbox将支持所有主要的浏览器包括Internet Explorer 8

取出min-height风格和使用CSS这样的:

.row { 
    display: flex; 
} 
.row .col-md-6 { 
    align-self: center 
} 

https://jsfiddle.net/4kLqukLs/7/


更多参考:Flexbox introduction