html5 - Replace picture background with video background -


what quickest way replace picture background have video background, while retaining of properties?

this code far:

<div id="hero"> <div id="bg"></div> <table id="outerdiv" cellpadding="0" cellspacing="0" border="0">     <tr>         <td valign="middle" id="innerdiv"> <div class="post-header"><img src="http://www.makemeapro.org/wp-content/uploads/2015/07/logo.png" style="max-width:100%;height:auto;"></div> <div class="post-header"><h1 style="color: #383838;">helping young professionals navigate world of work.</h1></div> <div align="center"><button class="btn">join revolution</button></div>         </td>     </tr> </table> </div> 

jsfiddle here: http://jsfiddle.net/zxqz7oe0/

one quick way replace picture background video, place video on top of picture, , make cover parent's area using object-fit. requires minor html , css changes:

html:

<div id="bg">      <video autoplay loop>           <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"/>           <source src="http://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg"/>      </video> </div> 

css:

#hero video {   width:100%;   height:100%;   object-fit:cover; /* resize video cover parent, background-size:cover */ }  #hero #bg {   /* styles #bg remain same, you'd need add */   /* 1 more, video overflows #hero hidden: */   overflow:hidden;  } 

you can see example working on jsfiddle: http://jsfiddle.net/zxqz7oe0/1/

one issue of solution object-fit not supported yet: chrome, firefox, , android ok, may face problem on firefox , mobile. , ie doesn't support @ all. (you can see browser support here.)

you use simple method, , have javascript fallback solution browsers not support object-fit. knowing video size, easy calculate width/height needed @ each moment when window loaded/resized.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -