'Can't Put Image Over Image
Edit: The solutions HAVE to have display: inline-block;
I'm trying to put an iframe over an image. However, no matter what I set the margin-right to, it stays in the same spot. About 1/5 of the background image.
HTML
<div class="backgroundimage">
<img src="http://truespeed.ca/wp-content/uploads/2016/06/tvscreen.png" alt="null" />
<iframe class="Youtube" width="479" height="269" src="https://www.youtube.com/embed/6ydYvG52K-E" frameborder="0" allowfullscreen></iframe>
</div>
CSS
.backgroundimage {
display: inline-block;
position: relative;
top: 70px;
bottom: 46px;
}
.Youtube {
position: absolute;
left: 280px;
bottom: 46px;
right: 380px;
}
And a picture of my issue:
Solution 1:[1]
It's all about the positioning. Just changed the margins and paddings.
.backgroundimage {
position: relative;
}
.Youtube {
position: absolute;
top: 11px;
left: 11px;
}
<div class="backgroundimage">
<img src="http://truespeed.ca/wp-content/uploads/2016/06/tvscreen.png" alt="null" />
<iframe class="Youtube" width="479" height="269" src="https://www.youtube.com/embed/6ydYvG52K-E" frameborder="0" allowfullscreen></iframe>
</div>
Solution 2:[2]
<style type="text/css">
.container { position:relative; }
.imgA1 { position:absolute; top: 0px; left: 0px; z-index: 1; }
.imgB1 { position:absolute; top: 70px; left: 100px; z-index: 3; }
</style>
<div class="container">
<img class="imgA1" src="image1.png">
<img class="imgB1" src="image2.png">
</div>
If you want you can add more image.
Solution 3:[3]
This is as similar as I can make to your code, while showing the image over the iframe:
img {
position:absolute;
left: 280px;
}
.backgroundimage {
display: inline-block;
position: relative;
top: 70px;
bottom: 46px;
}
.Youtube {
position: absolute;
left: 280px;
}
<div class="backgroundimage">
<iframe class="Youtube" width="479" height="269" src="https://www.youtube.com/embed/6ydYvG52K-E" frameborder="0" allowfullscreen></iframe>
<img src="http://truespeed.ca/wp-content/uploads/2016/06/tvscreen.png" alt="null" />
</div>
The main thing I've done is added position:absolute to the image
Solution 4:[4]
You'll never need to set both left and right when the width of an element is known. Just one of the two will suffice.
.backgroundimage {
display: inline-block;
position: relative;
top: 70px;
bottom: 46px;
}
.Youtube {
position: absolute;
top: 22px;
left: 20px;
}
Solution 5:[5]
Adjusted the absolute position of the video.
http://codepen.io/anon/pen/BLOdov
.backgroundimage {
display: inline-block;
position: relative;
top: 70px;
bottom: 46px;
}
.Youtube {
position: absolute;
left: 12px;
bottom: 50px;
right: 380px;
}
Solution 6:[6]
HTML
<div class="backgroundimage">
<img src="http://truespeed.ca/wp-content/uploads/2016/06/tvscreen.png" alt="null" />
<iframe class="Youtube" width="479" height="269" src="https://www.youtube.com/embed/6ydYvG52K-E" frameborder="0" allowfullscreen></iframe>
</div>
CSS
.backgroundimage {
display: inline-block;
position: relative;
top: 70px;
bottom: 46px;
}
.Youtube {
position: absolute;
left: 10px;
bottom: 52px;
}
Fiddel
Solution 7:[7]
I know it's late..
How about a very nice lightweight way of keeping it responsive by percentages? The resizing works flawlessly on all devices.
To add a width..add max-width:500px in the photo div, or whatever size you want, it will perfectly resize.
#container {
display: inline-block;
width: 100%;
height: auto;
}
#photo {
position: absolute;
width: 100%;
}
#movie {
position: absolute;
width: 100%;
max-width: 90%;
height: 75%;
top: 6.75%;
left: 4.25%;
border: none;
}
<div id="container">
<div id="photo">
<img src="http://truespeed.ca/wp-content/uploads/2016/06/tvscreen.png" width="100%" height="auto">
<div id="movie">
<iframe class="Youtube" width="100%" height="100%" src="https://www.youtube.com/embed/6ydYvG52K-E" frameborder="0" allowfullscreen> </iframe>
</div>
</div>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kind user |
| Solution 2 | Razia sultana |
| Solution 3 | Chris Lear |
| Solution 4 | darrylyeo |
| Solution 5 | Steven Ventimiglia |
| Solution 6 | Dhaval Ajani |
| Solution 7 |

