【问题标题】:iframe as a div background with visible content inside and clickableiframe 作为 div 背景,内部可见内容且可点击
【发布时间】:2019-12-09 16:24:53
【问题描述】:

我必须将 Vimeo 设置为包含 CTA 框的 div 的背景。 我找到了一些示例,并根据需要使视频背景全屏和响应成为可能。 但我发现里面的 CTA 框和按钮不可点击,因为用于将视频返回到 div 中的“z-index”。

玩 z-index 来回移动元素

.vimeo-wrapper {
   position: fixed;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   display:flex;
   pointer-events: none;
   overflow: hidden;
  
}
.vimeo-wrapper iframe {
   width: 100vw;
   height: 56.25vw; /* Given a 16:9 aspect ratio, 9/16*100 = 56.25 */
   min-height: 100vh;
   min-width: 177.77vh; /* Given a 16:9 aspect ratio, 16/9*100 = 177.77 */
   position: absolute;
   top: 50%;
   left: 50%;
   transform: translate(-50%, -50%);
   
}.content{
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:1;
  flex-wrap:wrap;
}.content,h2{
  width:100%;
  text-align:center;
  color:white;
}
 .CTA-wrapper{
  border:2px solid white;
  width:30%;
  padding-bottom:2%;
   
}
div button:hover {
  color: yellow;
}
<div class="vimeo-wrapper">
   <iframe src="https://player.vimeo.com/video/342964528?     background=1&autoplay=1&loop=1&byline=0&title=0" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
  <div class="content"> 
    <div class="CTA-wrapper">
      <h2>CTA Header</h2>
      <button class="btn-success">Click Me</button>
    </div>  
  </div>
</div>

预期:可点击的内部元素、全屏和响应式背景视频 结果:不是可点击的内部元素

【问题讨论】:

  • 下面的答案修复了按钮问题,但仍然存在其他问题,因为视频是整个网站和整个页面的背景。它必须在它的
    和其他元素内,然后它的
    才可见

标签: html css iframe background vimeo


【解决方案1】:

我认为它会起作用

css

.vimeo-wrapper {
   position: fixed;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   display:flex;
   pointer-events: none;
   overflow: hidden;
}
.content,h2{
  width:100%;
  text-align:center;
  color:white;
}
 .CTA-wrapper{
  border:2px solid white;
  padding-bottom:2%;

}
.vimeo-wrapper-box {
    width: 100%;
}
div button:hover {
  color: yellow;
}
.iframe_wrapper {
    position: relative;
    padding-bottom: 56.25%;
}
.vimeo-wrapper iframe {
   position: absolute;
   left: 0;
   right: 0;
   top: 0;
   bottom: 0px;
   width: 100%;
   height: 100%;
}
.vimeo-wrapper .content {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    text-align: center;
}

HTML

<div class="vimeo-wrapper">
    <div class="vimeo-wrapper-box">
        <h1>dfghfh</h1>
        <div class="iframe_wrapper">
           <iframe src="https://player.vimeo.com/video/342964528?background=1&autoplay=1&loop=1&byline=0&title=0" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
            <div class="content">
                <div class="CTA-wrapper">
                  <h2>CTA Header</h2>
                  <button class="btn-success">Click Me</button>
                </div>
            </div>
        </div>
    </div>
</div>

【讨论】:

  • 这解决了问题,但视频是整个页面的背景,而不仅仅是 div。
  • test

    如果你将前面的代码包装在这个容器中并在它之前得到一个

    但在外部容器中,你看不到h1

  • .content, h2 { 宽度: 100%;文本对齐:居中;白颜色; } 因为你被添加了颜色:#white.. 文本正在显示.. 更改颜色并检查
  • 我没有说 h2 是不可见的。颜色已经是白色了。如果您在 iframe 之前使用另一个元素,那么您将看不到这一点。我希望 iframe 在其 div 内全宽,而不是整个页面宽度。
【解决方案2】:
.CTA-wrapper{
 position: relative;
 z-index: 9999;
}

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签