html - 如何在全屏模式下保持 youtube 嵌入式视频居中

标签 html css youtube

我成功地将 youtube 嵌入视频居中,但问题是,当我进入全屏模式时,由于 transform:translate(-50%)属性

这是我的代码:

<div class="videoWrapper">
<iframe class="trailervideo" width="560" height="315" 
src="https://www.youtube.com/embed/TDwJDRbSYbw" frameborder="0" 
allowfullscreen></iframe>
<div>

CSS:

.videoWrapper {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
padding-top: 25px;
height: 0;
}
.videoWrapper iframe {
position: absolute;
max-width:560px;
max-height:315px;
width: 95%;
height: 95%;
left:50%;
transform:translate(-50%);
}

Link of fiddle

最佳答案

when I go to full-screen mode, the video position is out of the screen because of transform:translate(-50%) property

那么让我们把它扔掉,改用自动边距使元素居中:

.videoWrapper iframe {
    position: absolute;
    max-width:560px;
    max-height:315px;
    width: 95%;
    height: 95%;
    left:0;
    right:0;
    margin: auto;
}

关于html - 如何在全屏模式下保持 youtube 嵌入式视频居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44260662/

相关文章:

html - 我该如何将 flex 容器的中间文本居中?

html - 浏览器正在覆盖我代码中的所有元素并将它们变成链接

javascript - 如何遍历<tr>中的元素

html - 移动设备上的 Youtube iframe,宽度不佳

javascript - 使用javascript使图像用作字体大小调整按钮

javascript - React 中 HTML 元素的条件渲染?

image - 高级 CSS 还是图像?

css - 忽略 nowrap 的 Firefox 文本溢出(Chrome 有效)

java - 代表该网站(而不是用户)从 Google App Engine 网站在 YouTube 上发布视频

video - html5模式下youtube视频顶部的水平条纹