Flexbox 中的 HTML CSS 视频

标签 html css video flexbox

<!DOCTYPE html> 
<html>
<style>
.d1 {
    background: blue;
    padding: 10px;
    display: flex;
}
video {
    margin: 10px;
    width: 100%;
    max-width: 500px;
}
</style>
<body> 

<div class="d1">
  <video controls>
    <source src="mov_bbb.mp4" type="video/mp4">
    <source src="mov_bbb.ogg" type="video/ogg">
    Your browser does not support HTML5 video.
  </video>
</div>

</body> 
</html>

我在 flexbox 中使用了一个 video ,除了两点之外,代码工作正常:1) 视频大小不合适适合下面的控制线。我怎样才能让它合适?我认为这与对齐有关... 2) 我希望仅水平调整 video 的大小。为此,我搜索并使用了 width: 100% 并且它有效,但是当我调整它的大小时,正确的部分似乎忽略了我给它的 margin :

enter image description here

最佳答案

 justify-content: center;
    align-items: center;

将上面的样式添加到 css 中。试试下面的代码片段

<!DOCTYPE html>
<html>
<style>
  .d1 {
    background: blue;
    padding: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  video {
    margin: 1rem;
    width: 100%;
  }
</style>

<body>

  <div class="d1">
    <video controls>
    <source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
    <source src="mov_bbb.ogg" type="video/ogg">
    Your browser does not support HTML5 video.
  </video>
  </div>

</body>

</html>

关于Flexbox 中的 HTML CSS 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48599918/

相关文章:

java - 当我从一台 PC 有双头或三头时,如何知道分辨率屏幕宽度和高度?

video - 使用 ffmpeg 批量转换视频,同时复制文件夹层次结构中的其他文件

html - CSS 禁用水平滚动在本地服务器上工作,但不在域上

javascript - 如何将 Facebook 与我自己的点赞按钮集成

css - 将css文件导入特定组件 react 应用程序

css - 去除 ng-deep 对组件破坏的影响

javascript - 为什么这个视频无法播放? HTML5 Canvas

javascript - 使用框中给出的数据完成 url 并转到该 url

javascript - 如何汇总单选按钮选择值的总数(字母,而不是数字)?

javascript - 使用 JQuery 选择 li 元素内的第一个 anchor