HTML/CSS : YouTube iframe as background with controls usable and button overlay

标签 html css button youtube controls

我只是用 HTML/CSS 来构建一个页面,上面有一个带有按钮的 youtube 视频。

* { box-sizing: border-box; }
.video-background {
  background: #000;
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: -99;
}
.video-background iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
html, body {
    height: 100%;
    margin: 0;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
}
.btn-wrapper {
  width: 290px;
  height: 110px;
  position: relative;
  margin: 40px auto 0;
}
.btn-wrapper:hover .btn-inner {
  top: -4px;
  transform: scale(1, 1);
  cursor: pointer;
}
.btn-wrapper__container {
  border-bottom: 2px solid #15b5e2;
  position: absolute;
  width: 100%;
  height: 80px;
}
.btn-wrapper__container:before, .btn-wrapper__container:after {
  border-bottom: 2px solid #15b5e2;
  width: 96%;
  left: 2%;
  bottom: -8px;
  content: "";
  position: absolute;
}
.btn-wrapper__container:after {
  width: 92%;
  left: 4%;
  bottom: -14px;
}
.btn-wrapper__container .btn-inner {
  width: 104.2%;
  height: 100%;
  position: absolute;
  top: 20px;
  left: -2.1%;
  border: 2px solid #15b5e2;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Source Code Pro', monospace;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 18px;
  background: #10131c;
  transform: scale(0.96, 0.96);
  transition: all 0.3s;
  z-index: 4;
}
.btn-wrapper__container .btn-inner__text {
  text-decoration: none;
  color: #15b5e2;
}
<div class="video-background">
  <iframe src="https://www.youtube.com/embed/TMzouTzim0o?controls=1&showinfo=0&rel=0&autoplay=1&loop=1&playlist=W0LHTWG-UmQ" frameborder="0" allowfullscreen></iframe>
</div>


<div class="btn-wrapper">
  <div class="btn-wrapper__container">
    <div class="btn-inner">
      <a class="btn-inner__text" href="#">Hover Me</a>
    </div>
  </div>
</div>

虽然没有添加按钮,但视频在背景中显示,响应式全屏,并启用了控制元素。如果我添加悬停按钮,我将无法再控制后台视频(360 度视频)。

我怎样才能启用视频控件并仍然可以使用按钮?

不幸的是,我不是编码专家,我将教程中找到的这些代码拼凑在一起。

最佳答案

从类 .video-background {...} 中删除 css 属性 z-index: -99,这将解决问题。

* {
  box-sizing: border-box;
}

.video-background {
  background: #000;
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  /* z-index: -99; */ /* Remove this line  */
}

.video-background iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

.btn-wrapper {
  width: 290px;
  height: 110px;
  position: relative;
  margin: 40px auto 0;
}

.btn-wrapper:hover .btn-inner {
  top: -4px;
  transform: scale(1, 1);
  cursor: pointer;
}

.btn-wrapper__container {
  border-bottom: 2px solid #15b5e2;
  position: absolute;
  width: 100%;
  height: 80px;
}

.btn-wrapper__container:before,
.btn-wrapper__container:after {
  border-bottom: 2px solid #15b5e2;
  width: 96%;
  left: 2%;
  bottom: -8px;
  content: "";
  position: absolute;
}

.btn-wrapper__container:after {
  width: 92%;
  left: 4%;
  bottom: -14px;
}

.btn-wrapper__container .btn-inner {
  width: 104.2%;
  height: 100%;
  position: absolute;
  top: 20px;
  left: -2.1%;
  border: 2px solid #15b5e2;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Source Code Pro', monospace;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 18px;
  background: #10131c;
  transform: scale(0.96, 0.96);
  transition: all 0.3s;
  z-index: 4;
}

.btn-wrapper__container .btn-inner__text {
  text-decoration: none;
  color: #15b5e2;
}
<div class="video-background">
  <iframe src="https://www.youtube.com/embed/TMzouTzim0o?controls=1&showinfo=0&rel=0&autoplay=1&loop=1&playlist=W0LHTWG-UmQ"
    frameborder="0" allowfullscreen></iframe>
</div>
<div class="btn-wrapper">
  <div class="btn-wrapper__container">
    <div class="btn-inner">
      <a class="btn-inner__text" href="#">Hover Me</a>
    </div>
  </div>
</div>

关于HTML/CSS : YouTube iframe as background with controls usable and button overlay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52551348/

相关文章:

html - 为整个部分加下划线而不考虑文本

javascript - 将一个计算数组中对象数量的函数放入另一个函数中

javascript - 水平和垂直对齐伪元素的内容

html - 通过 https 加载样式表时出现问题

python - 在 HTML 按钮中引用 Django URL

javascript - 保持 div 居中,保持宽高比并垂直或水平调整大小

html - 如何在 MVC (asp.net) 中为进入域和根目录的应用程序编写 css?

css - 输出文件夹中的样式表文件

python - 如何使用 Tkinter 按钮退出 Python?

android - 更新按钮上的文本