【问题标题】:creating a video container that covers the whole screen创建一个覆盖整个屏幕的视频容器
【发布时间】:2020-02-03 09:56:16
【问题描述】:

我想创建一个覆盖整个屏幕的视频容器

并且容器内的视频覆盖整个容器并且不溢出意味着容器适应整个屏幕尺寸。

并做出相应的反应。

目前视频正处于全高度..我不想要那个

我希望它的高度限制在屏幕大小并且没有滚动。

我的html代码是

<div class="video-container">
  <div class="video-wrapper">
    <video autoplay controls>
      <source src="../../assets/movies/joker.mp4" type="video/mp4" />
      Your browser does not support the video tag.
    </video>
  </div>
</div>

我的css代码是:

.video-container {
  display: block;
  max-width: 100%;
  min-width: 200px;
}
.video-wrapper {
  background: #000;
  border-radius: inherit;
  overflow: hidden;
  position: relative;
  z-index: 0;
}
.video-container video {
  border-radius: inherit;
  height: auto;
  vertical-align: middle;
  width: 100%;
}
video {
  max-width: 100%;
  object-fit: contain;
}

请帮我解决这个问题..提前谢谢。

【问题讨论】:

  • 尝试在 vhvw 中搜索 css

标签: html css html5-video


【解决方案1】:

CSS:

* {
    box-sizing: border-box;
  }

  body {
    margin: 0;
    font-family: Arial;
    font-size: 17px;
  }

  video {
    position: fixed;
    right: 0;
    bottom: 0;
    width: 100%; 
    height: 100%;
  }

HTML:

<body>
    <script src="./index.js"></script>
    <video autoplay controls>
        <source src="../../assets/movies/joker.mp4" type="video/mp4">
        Your browser does not support HTML5 video.
    </video>
</body>

【讨论】:

    【解决方案2】:

    这样的元标记会有所帮助:

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    您需要更改宽度和高度,CSS 具有视图高度和视图宽度的可能性,因此它适合屏幕。如上所述:

    .video-wrapper{
    height: 100vh;
    width: 100vh;
    }
    

    【讨论】:

    • 你的意思是宽度:100vw?
    • 是的,我没睡过^^
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多