css – Html5视频背景,将视频中心保持在中心位置

前端之家收集整理的这篇文章主要介绍了css – Html5视频背景,将视频中心保持在中心位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图保持背景视频的中心,无论用户拖动视频多大.当我滚动较小时,它正在切断视频的右侧.这是我有的:
  1. <section id="home">
  2. <div class="video_shader"></div>
  3. <div class="video_contain">
  4. <video autoplay="" loop="" poster="img/still.jpg" id="bgvid">
  5. <source src="/realWebm.webm" type="video/webm" />
  6. <source src="/realdeal.mp4" type="video/mp4">
  7. <source src="/reaOg.ogv" type="video/ogg" />
  8. </video>
  9. </div>
  10. </section>
  11.  
  12. .video_contain{
  13. display: block;
  14. position: absolute;
  15. background-position: center center;
  16. background-repeat: no-repeat;
  17. background-size: cover;
  18. top: 0;
  19. left: 0;
  20. right: 0;
  21. bottom: 0;
  22. width: 100%;
  23. height: 100%;
  24. }
  25.  
  26. video {
  27. min-width: 100%;
  28. min-height: 100%;
  29. z-index: -100;
  30. background-position: center;
  31. background-size: cover;
  32. }
  33.  
  34. #home {
  35. width: 100vw;
  36. height: 100vh;
  37. display:block;
  38. position: relative;
  39. }

我希望视频的中心始终是页面的中心,即使双方被切断 – 这实际上是理想的,如果这样发生的话.感谢任何帮助.谢谢阅读!

解决方法

以下是我通常做背景视频的方式,以及我如何为 stre.am着陆页进行操作:
  1. .video_contain {
  2. position: absolute;
  3. top: -50%;
  4. left: -50%;
  5. width: 200%;
  6. height: 200%;
  7. }
  8.  
  9. video {
  10. position: absolute;
  11. top: 0;
  12. bottom: 0;
  13. right: 0;
  14. left: 0;
  15. margin: auto;
  16. min-height: 50%;
  17. min-width: 50%;
  18. }

猜你在找的CSS相关文章