html - Layering iframe and video -


i have video want play on top of iframe , remove when finishes can't make video appear above iframe. there trick it? i've tried css z-index doesn't help. have code this:

<html> <head> <title>enormous wedding iii</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body>  <div class = "container"><span> <div id = "game"><iframe src='...'></div> <div id = "video"><video autoplay> <source src="menu.mp4" type="video/mp4"> </video></div> </span></div>  <script>     var video = document.getelementsbytagname('video')[0];     var game = document.getelementsbytagname('iframe')[0];      video.onended = function(e) {       video.style.display = "none";     }; </script>  </body></html> 

and css file:

    html, body, .container {     height: 100%; } .container {     display: -webkit-flexbox;     display: -ms-flexbox;     display: -webkit-flex;     display: flex;     -webkit-flex-align: center;     -ms-flex-align: center;     -webkit-align-items: center;     align-items: center;     justify-content: center; }  #game {     z-index: 1; }  #video {     z-index: 2; } 

why doesn't work , how can make video appear on top of iframe?

use position: absolute; on child elements , position: relative; on parent.

.container {     position: relative; } iframe {     position: absolute;     top: 0;     left: 0;     z-index: 1; } video {     position: absolute;     top: 0;     left: 0;     z-index: 2; } 

z-index requires position set relative, absolute or fixed. doing using position absolute can put elements want within next element tree position relative, in case .container

the example jsfiddle shows in action


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -