如何解决居中 <video> 问题
我用这种方式:
.centr {
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%,-50%);
-moz-transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
-o-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
}
问题是画中画,不到位
解决方法
在父 div 中居中 <video>
元素的一种方法是使用 flexbox:
.container {
/* just styling,nothing important */
background-color: gray;
width: 500px;
height: 200px;
/* note these lines below */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
video {
width: 300px;
height: 150px;
background-color: #000;
}
<div class="container">
<video></video>
</div>
要使自动边距起作用,中心类必须有一个宽度:
.center {
margin: 0 auto;
width: 400px;
}
然后,我将中心类应用到视频本身,而不是容器:
<video class='center'>
</video>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。