值较低的Z-index仍会显示在其他div之上

时间:2019-02-12 11:27:59

标签: html css z-index

为什么VideoDivNote仍然显示在VideoDiv上方,尽管z索引较低?使用<div>时出现问题,或者我在做什么 还有错吗?

<style>

    #VideoDiv
    {position: absolute;
    left: 3%;
    bottom: 5%;
    z-index: 999;
    background-color: #DCDCDC;
    height: 260px;
    width: 424px;
    text-align: center;
    border: 1px solid #d3d3d3;
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px;
    border-radius: 20px;
    }

    #VideoDivNote
    {height: 30px;
    position: relative;
    width: 300px;
    margin: auto;
        left: 0px;
        right: 0px;
        bottom:0px;
    background-color: rgba(8, 8, 8, 0.7);
    -webkit-border-radius: 0px 0px 15px 15px;
    -moz-border-radius: 0px 0px 15px 15px;
    border-radius: 0px 0px 15px 15px;
    z-index: 1;
    }


    #VideoMessage
    {color: #fff;
    font-family: acme;
    position: relative;
    bottom: -6px;
    z-index: 2;
    }

 </style>

    <div id="VideoDiv">

        <div id="VideoPlayer"></div>
        <div id="VideoDivNote"><span id="VideoMessage">z-index not working</span></div>

    </div>

2 个答案:

答案 0 :(得分:0)

感谢Temani Afif进行详细说明。 您需要从#VideoDiv中删除z-index并使用z-index:-1;在#VideoDivNote ID中。请参见下文或查看此link

    #VideoDiv
    {position: absolute;
    left: 3%;
    bottom: 5%;
    background-color: #DCDCDC;
    height: 260px;
    width: 424px;
    text-align: center;
    border: 1px solid #d3d3d3;
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px;
    border-radius: 20px;
    }

    #VideoDivNote
    {height: 30px;
    position: relative;
    width: 300px;
    margin: auto;
        left: 0px;
        right: 0px;
        bottom:0px;
    background-color: rgba(8, 8, 8, 0.7);
    -webkit-border-radius: 0px 0px 15px 15px;
    -moz-border-radius: 0px 0px 15px 15px;
    border-radius: 0px 0px 15px 15px;
    z-index: -1;
    }


    #VideoMessage
    {color: #fff;
    font-family: acme;
    position: relative;
    bottom: -6px;
    z-index: 2;
    }
<div id="VideoDiv">
   <div id="VideoPlayer"></div>
   <div id="VideoDivNote"><span id="VideoMessage">z-index not working</span></div>
</div>

答案 1 :(得分:-3)

请确保您的邮件div的z-index值高于另一个

<style>

    #VideoDiv
    {position: absolute;
    left: 3%;
    bottom: 5%;
    z-index: 999;
    background-color: #DCDCDC;
    height: 260px;
    width: 424px;
    text-align: center;
    border: 1px solid #d3d3d3;
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px;
    border-radius: 20px;
    }

    #VideoDivNote
    {height: 30px;
    position: relative;
    width: 300px;
    margin: auto;
        left: 0px;
        right: 0px;
        bottom:0px;
    background-color: rgba(8, 8, 8, 0.7);
    -webkit-border-radius: 0px 0px 15px 15px;
    -moz-border-radius: 0px 0px 15px 15px;
    border-radius: 0px 0px 15px 15px;
    z-index: 1;
    }


    #VideoMessage
    {color: #fff;
    font-family: acme;
    position: relative;
    bottom: -6px;
    z-index: 1000;
    }

 </style>

    <div id="VideoDiv">

        <div id="VideoPlayer"></div>
        <div id="VideoDivNote"><span id="VideoMessage">z-index not working</span></div>

    </div>