First of all, you cannot use <img> in this way, because it is an element that cannot contain other elements.
All you have to do is put your image as the background for the div and then display the video with the correct position:
<div id="tv_container"> <video width="320" height="240"> <source src="video/video.mp4" type="video/mp4" /> </video> </div> <style> #tv_container { background: url('images/tv.png') no-repeat top left transparent; width: 400px; height: 300px; position: relative; } #tv_container video { position: absolute; top: 30px; left: 40px; } </style>
or instead of position: relative; and position: absolute; you can use margin: 30px 0px 0px 40px; for #tv_container video (but the trick with position better if you want to add another element to #tv_container .
I assumed that the TV image is larger than video , but you have to configure a few things in order to display it correctly.
Inspired by Guilherme J. Santos's answer, I suggest you use a TV image as a layer on top of video , because in this way you can use an image with a TV screen, which should not be a strict rectangle. Of course, part of the video will then be cropped, but it will look like a TV screen.
<div id="tv_container"> <video width="320" height="240"> <source src="video/video.mp4" type="video/mp4" /> </video> </div> <style> #tv_container { width: 400px; height: 300px; position: relative; } #tv_container:after { content: ''; display: block; background: url('images/tv.png') no-repeat top left transparent; width: 100%; height: 100%; left: 0px; top: 0px; position: absolute; z-index: 10; } #tv_container video { position: absolute; top: 30px; left: 40px; z-index: 5; } </style>
Make sure that the z-index layer (which in this case is the #tv_container:after pseudo- #tv_container:after ) is larger than the video z-index . And there is one thing: your video will not be clickable (because it is under the layer) According to @brichins comment, it is also possible to make the video clickable under the layer (thanks!).
Of course, part of the TV screen should be transparent!
Wirone
source share