代码之家  ›  专栏  ›  技术社区  ›  kadina

无法使用z索引在视频上显示按钮或文本

  •  0
  • kadina  · 技术社区  · 8 年前

    我需要在视频上显示播放按钮。我试过使用z-index。但它似乎不起作用。下面是html代码

    html:

    <!DOCTYPE html>
    <html>
        <head>
            <title>text</title>
            <link rel="stylesheet" href="test.css">
        </head>
        <body style="overflow: hidden; margin: 0px;">
            <div id="d1">
                <video id="videoID" src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" autoplay>
                <div id="d2">
                    <h1 id="h">I am heading</h1>
                    <!--<button type="button" id="play-pause" class="play">Play</button>-->
                </div>
            </div>
        </body>
    </html>
    

    CSS:

    #d1
    {
        font-family: 'Avenir', Helvetica, Arial, sans-serif;
        color: #2c3e50;
        margin-top: 10px;
        width: 55%
    }
    
    #videoID
    {
        width: 100%;
        height: 100%;
        position: absolute;
        z-index: 10;
    }
    
    #d2 {
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 15;
        left: 100px;
        top: 100px;
    }
    

    “位置:绝对”应在视频顶部显示标题。它不起作用。我把d2的z指数加到了15。但还是没用。我无法在视频上显示该按钮。如果有任何问题以及如何解决,请任何人帮助我。

    1 回复  |  直到 8 年前
        1
  •  1
  •   sol    8 年前

    <video> 不是自动关闭元件。 Info from MDN

    #d1 {
      font-family: 'Avenir', Helvetica, Arial, sans-serif;
      color: #2c3e50;
      margin-top: 10px;
      width: 55%
    }
    
    #videoID {
      width: 100%;
      height: 100%;
      position: absolute;
      z-index: 10;
    }
    
    #d2 {
      position: absolute;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: flex-start;
      height: 100%;
      z-index: 15;
      left: 100px;
    }
    <div id="d1">
      <video id="videoID" src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" autoplay></video>
      <div id="d2">
        <h1 id="h">I am heading</h1>
        <button type="button" id="play-pause" class="play">Play</button>
      </div>
    </div>