简体   繁体   English

如何在单元格的中间垂直对齐视频?

[英]How to vertically align a video in the middle of a cell?

I'm trying to align a video in the middle of a fixed height cell, in a way that the overflow at the top and bottom is hidden. 我正在尝试在固定高度的单元格中间对齐视频,以隐藏顶部和底部的溢出。

Up to now i've got: 到目前为止,我已经:

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="150" style="display: block; overflow: hidden; vertical-align: middle;">
    <div style="position: relative;">
      <video autoplay loop width="100%" style="display: block;">
        <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
      </video>
    </div>
    </td>
  </tr>
</table>

However the "vertical-align: middle;" 但是“ vertical-align:middle;” in the "td" doesn't seem to do anything. 在“ TD”似乎没有做任何事情。

I'm looking to see only the middle 150 pixels, but currently it's showing the top 150... 我希望只看到中间的150像素,但目前显示的是顶部150像素...

For anyone who is able to help, a link to my JSfiddle example: https://jsfiddle.net/xtxkm02a/1/ 对于任何能够提供帮助的人,请指向我的JSfiddle示例的链接: https ://jsfiddle.net/xtxkm02a/1/

Thanks. 谢谢。

Here is the code, additional to my comment. 这是代码,除了我的评论。

 table { height: 300px; border: 1px solid #000; } table td { border: 1px solid #f00; overflow: hidden; vertical-align: middle; height: 30px; } .video { overflow: hidden; height: 150px; } .video video { width: 100%; margin-top: -75px; } 
 <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="center" style=""> <div class="video"> <video loop> <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"> </video> </div> </td> </tr> </table> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM