javascript - 在 html 和 css 中的视频背景上添加按钮。 Z 索引不起作用

标签 javascript jquery css html

尝试在 html 和 css 中的全屏视频背景上添加一个按钮。 Z-index 无法正常工作,分别尝试了每个元素,并且它们有效。但它们不会堆叠在一起。我可能错过了一个我不知道的重要链接。 添加 html 和 css 代码

<!DOCTYPE html>
<html>
<title>homepage</title>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet2.css"/>
</head>
    <body>
    <video id ="videobg" preload="auto" autoplay="true" lopp="loop">
<source src="secret.3gp" > video not supported<video/>
</video>
<div id="button">
<img src= "button.png"/>
</div>
</body>
</html>

CSS FILE 

#button{
left: 490px;
  top: 560px;
  position:fixed;
  z-index:1
}
#videobg{
    min-width:100%;
    min-height:100%;
    width: auto;
    height:auto;
    position:fixed;
    z-index:-1;
}

最佳答案

尝试将视频包装在 div 中。这对我有用:jsfiddle

   <!DOCTYPE html>
    <html>
        <head>
            <link type="text/css" rel="stylesheet" href="stylesheet2.css"/>
            <title>homepage</title>
        </head>
        <body>
            <div id="videowrap">
                <video id ="videobg" preload="auto" autoplay="true" loop>
                    <source src="secret.3gp" >
                </video>
            </div>
            <div id="button">
                <img src= "button.png"/>
            </div>
        </body>
    </html>

CSS 文件

#button{
left: 490px;
  top: 560px;
  position:fixed;
  z-index:1
}
#videobg{
    min-width:100%;
    min-height:100%;
    width: auto;
    height:auto;
    position:fixed;
    z-index:-1;
}

关于javascript - 在 html 和 css 中的视频背景上添加按钮。 Z 索引不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40251913/

相关文章:

javascript - 我如何使用jquery以特定 Angular 滑动div内容

javascript - 用于电子邮件验证的 UI 对话框不显示任何对话框

javascript - 制作一个jquery函数来返回元素

jquery - Aframe 中用于定位的动画不起作用

javascript - 如何禁用动态创建的 <li> 元素?

javascript - 使用 jquery 替换 li 文本而不更改其他元素

javascript - 如何使用 JavaScript 验证输入字段

javascript - 如何在处理请求时显示正在加载的 gif?

c# - 为水平表格的列引入分页符

alignment - css - 在显示为 :inline-block 的元素上添加垂直空间