'How to make 2 videos side by side, centered, and responsive
I am trying to add 2 videos side by side which are centered and spaced out correctly, and then want to make them responsive with the second video dropping down below the first video so that it can appear stacked on mobile devices. My Html that I am working with is:
<div id="wrapper">
<div id="home1">
<video width="400" height="300" poster="images/video.jpg" controls="controls" preload="none">
<source type="video/mp4" src="images/stories/home1.mp4" />
</video>
</div>
<div id="home2">
<video width="400" height="300" poster="images/video.jpg" controls="controls" preload="none">
<source type="video/mp4" src="images/stories/home2.mp4" />
</video>
</div>
</div>
and my css so far is:
#wrapper {
width: 920px;
height: 350px;
margin: 0 auto;
}
#home1 {
width: 400px;
height: 300px;
float: left;
}
#home2 {
width: 400px;
height: 300px;
float: right;
}
@media (max-width:767px) {
.home1 {
position: relative;
padding-bottom: 56.25%; /* 16/9 ratio */
padding-top: 30px; /* IE6 workaround*/
height: 0;
overflow: hidden;
}
.home2 {
margin-left: 0;
}
}
Thanking you in advance
Solution 1:[1]
I did some modifications in your html and css, test it yourself.
HTML
<div id="wrapper">
<video id="home1" width="400" height="300" poster="images/video.jpg" controls="controls" preload="none">
<source type="video/mp4" src="images/stories/home1.mp4" />
</video>
<video id="home2" width="400" height="300" poster="images/video.jpg" controls="controls" preload="none">
<source type="video/mp4" src="images/stories/home2.mp4" />
</video>
<div class="clear"></div>
</div>
CSS
#wrapper {
width: 920px;
height: auto;
margin: 0 auto;
}
#home1 {
width: 47.5%;
height: 300px;
float: left;
margin-right: 5%;
}
#home2 {
width: 47.5%;
height: 300px;
float: left;
}
.clear{
clear: both;
}
@media (max-width:767px) {
#wrapper{
width: 100%;
height: auto;
}
#home1 {
width: 100%;
height: auto;
float: none;
}
#home2 {
width: 100%;
height: auto;
float: none;
}
}
Solution 2:[2]
Have you tried adding something to your media query to remove the floats and maximize the width? edit: you might actually need to be more specific since you're using #'s on the divs so #home1, #home2 { width: 100%; float: none; }
– example here http://codepen.io/evanrbriggs/pen/pwkHj
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 | Jefferson Ribeiro |
Solution 2 | Evan |