【问题标题】:Inserting a video over an image with css and html使用 css 和 html 在图像上插入视频
【发布时间】:2016-11-16 03:24:47
【问题描述】:

我希望在我的网站http://176.32.230.43/testdigitalmarketingmentor.co.uk/ 上创建一个图形,其中从笔记本电脑的图片中播放视频(因此看起来视频正在笔记本电脑屏幕上播放)。我还希望它具有移动响应能力(即根据屏幕尺寸重新缩放)。您可以向下滚动到“Showreel”以查看到目前为止我使用以下 css 和 html 管理的内容...任何帮助/建议/指导将不胜感激!

#laptop-panel {
        position: relative;
        width: auto;
        height: 625px;
        overflow: hidden;
    }

    #laptop-panel-tv {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: url('http://176.32.230.43/testdigitalmarketingmentor.co.uk/wp-content/uploads/2016/07/laptop-1000x728-trans.png') no-repeat center;
    z-index: 10;
    }

    #laptop-panel-content-overlay {
        position: absolute;
        top: 70px;
        width: 100%;
        height: 444px;
        z-index: 12;

    .embed-container {
        position: relative;
        padding-bottom: 56.25%;
        padding-top: 30px;
        height: 0;
        overflow: hidden;
        max-width: 100%;
        height: auto;
      }
.video-container {
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 30px; height: 0; overflow: hidden;
}
 
.video-container iframe,
.video-container object,
.video-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
<div id="laptop-panel">
    <div id="laptop-panel-tv"></div>
    <div id="laptop-panel-content-overlay">
    <div id="laptop-panel-content">
        <div class="embed-container">
        <div style="width: 683px; " class="wp-video">
<!--[if lt IE 9]>    <script>document.createElement('video');</script><![endif]-->

   <div class="video-container">
<iframe src="https://www.youtube.com/embed/BhEWkcyXYwg?rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
   </div></div></div>            
   </div>
</div>

【问题讨论】:

  • 这有什么问题?
  • 视频没有出现在网站上,它只是一个带有播放按钮等的黑框,但点击时它没有任何作用。
  • 问题似乎与播放器正在处理的 MIME 类型有关。为什么不直接嵌入带有默认 html5 属性的 youtube 播放器? support.google.com/youtube/answer/171780?hl=en
  • 我可以,请问我该如何实现?
  • 刚刚为您发布了一个解决方案。希望能帮助到你。如果有,请将其标记为答案。干杯

标签: html css


【解决方案1】:

你可以用这样的东西吗?这也有助于在 Youtube 上获得更多观看次数。

    #laptop-panel {
        position: relative;
        padding-top: 25px;
        padding-bottom: 67.5%;
        height: 0;
    }
    #laptop-panel iframe {
        box-sizing: border-box;
        background: url(http://176.32.230.43/testdigitalmarketingmentor.co.uk/wp-content/uploads/2016/07/laptop-1000x728-trans.png) center center no-repeat;
        background-size: contain;
        padding: 11.7% 17.9% 15.4%;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
  <div id="laptop-panel">
        <iframe src="https://www.youtube.com/embed/BhEWkcyXYwg?rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
    </div>

编码愉快!

【讨论】:

  • 我已经尝试过了,但它似乎并没有改变任何东西......我仍然只是得到一个带有播放图标的黑框,但点击时它没有做任何事情。我已经尝试清除缓存但没有区别...有什么想法吗?
  • 我为你做了一支笔。你能看看这个吗? codepen.io/IsabelInc/pen/wWPQxw
  • 这很好用,知道如何让它响应移动吗?非常感谢您的帮助,谢谢!
  • 添加宽度:100% 应该可以解决问题。以下是一些响应式视频示例的链接coolestguidesontheplanet.com/videodrome/youtube希望这能回答您的问题。祝你好运
  • 这适用于视频,但我如何使用它以便笔记本电脑边框也调整大小?目前,在移动设备上,视频播放良好,但顶部和底部有黑条,覆盖了笔记本电脑的图像。
猜你喜欢
  • 2016-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-15
  • 2019-10-15
相关资源
最近更新 更多