Using Bootstrap 3 I have managed to get a respinsive video working on my homepage, you can see it working here: http://www.infiniteideamedia.com/test/ The only issue I'm having with it is that on devices smaller than video width (1280px) the video is cut off on only 1 side. I would prefer it kept the video center and cut the video off both sides. Is this possible? Its the same issue with poster which is shown instead on iOS devices instead of the video. Here's the code in place at the moment:
HTML:
<div id="vid">
<video autoplay loop poster="img/Poster.jpg">
<source src="img/homevideo.webm" type="video/webm"/>
<source src="img/homevideo.mp4" type="video/mp4"/>
</video>
</div>
CSS:
#vid
{
position:absolute;
height:100%;
width:100%;
overflow: hidden;
}
#vid video {
width:auto;
min-width:100%;
height:auto;
min-height:500px;
}
I've come to the conclusion that I might need to use an JS alternative, any tips on how to implement that would be great.
After a bit research, another post on here actually. Doing this does what I need:
position: absolute;
top: -9999px;
bottom: -9999px;
left: -9999px;
right: -9999px;
margin: auto;
Doing what you propose, I've never seen it unless it's a background image. Under the size where it it starts going left, you can use responsive embedding. Otherwise, there's a lot of math, you'd essentially have to pick some min-widths or max-widths and start positioning the #vid outside the viewport but by how much would have to be guessed.
DEMO: https://jsbin.com/zowuze/1/
#vid {
position: relative;
padding-bottom: 40%;
height: 0;
overflow: hidden;
max-width: 100%;
height: auto;
}
#vid video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#media (min-width:1280px) {
#vid {
position: absolute;
height: 100%;
width: 100%;
overflow: hidden;
padding: 0;
height:500px;
}
#vid video {
width: auto;
min-width: 100%;
height: auto;
position: static;
}
}
Related
I have a video playing in the background of my top div. It looks fine when the screen is full size, but when I resize the browser window to see how it will look on smaller screens, the height of the div remains the same, leaving a big empty space between the background video and the next div.
Here is a preview of the site if you'd like to see for yourself, along with the specific code. https://codepen.io/CarlyWysocki/pen/YYaBOd
HTML:
<div class="jumbotron" id="top">
<video autoplay loop>
<source src="https://videos2.sendvid.com/03/25/up5p1yhu.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<div class="container text-center">
<h1>Mac Demarco</h1>
<h4>Canadian singer-songwriter, multi-instrumentalist and producer.</h4>
<i class="fa fa-chevron-circle-down"></i>
</div>
</div>
CSS:
video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: auto;
}
.jumbotron {
padding-top: 30px;
padding-bottom: 30px;
margin-bottom: 30px;
color: inherit;
background-color: #eee;
height: 100%;
overflow: hidden;
position: relative;
}
.container {
position: relative;
}
If it just stays in the center, you can add css media queries resizing appropriately. One could also just use a picture for small screens via media queries.
Using the referenced stack overflow answer:
.video-container {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
.video-container video {
/* Make video to at least 100% wide and tall */
min-width: 100%;
min-height: 100%;
/* Setting width & height to auto prevents the browser from stretching or squishing the video */
width: auto;
height: auto;
/* Center the video */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
I'm building a website that has an autoplaying video as the hero element, and I currently have the video set to the following css:
#video-background {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
width: auto !important;
height: auto !important;
z-index: -100;
}
The purpose of which is to allow it to be full width. The fixed position is needed because the content below the video needs to be able to scroll over the video.
Unfortunately, even with the negative z-index, the video prevents you from clicking on content further down the page. It's still overlaying everything. When I right click anywhere the play, pause, unmute, etc. controls come up.
Not really sure how to keep this from happening. I've tried to play around with some of the settings, but anything (that I've tried, at least) that makes it full width ends up causing it to overlay everything.
Here's the html:
<video autoplay="" loop="" id="video-background" muted="" style="width: 100%; height: 100%;">
<source src="http://beta.mattgrossdesign.com/sites/default/files/wood%20autumn-HD.mp4" type="video/mp4">
</video>
EDIT: Solved it with a little help from a coworker. Here's the CSS:
div#layer_slider_1 {
height: auto;
position: fixed;
top: 0;
width: 100%;
z-index: 0;
}
div#after_layer_slider_1 {
margin-top: 800px;
}
div#layer_slider_1 is the parent div. The div#after_layer_slider_1 is obviously the div right after it.
Thanks for the input.
Add this CSS property
html, body {
width:100%;
height:100%;
}
Solved it with a little help from a coworker. Here's the CSS:
div#layer_slider_1 {
height: auto;
position: fixed;
top: 0;
width: 100%;
z-index: 0;
}
div#after_layer_slider_1 {
margin-top: 800px;
}
div#layer_slider_1 is the parent div. The div#after_layer_slider_1 is obviously the div right after it. Needed to make the div below it overlay the video in order to avoid it from covering the whole page, even with the z-index.
Thanks for the input.
Hi I built a responsive theme to embed vimeo videos.
Here is my CSS:
.vimeo-container {
position: relative;
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
max-width: 100%;
height: auto;
}
.vimeo-container iframe,
.vimeo-container object,
.vimeo-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
And here is my html:
<div class="vimeo-container">
<!-- video iframe goes here -->
</div>
It works well and is responsive. Now I want to keep this responsiveness but make this video look like a background, so I thought of adding an overlay with text on top of it. Something like what is done on this Site.
How to keep the responsiveness and add an overlay with text to make it similar to the mentioned site above?
For the overlay, you can add an absolutelty postionned DIV inside your container. I changed your CSS a bit to make it more fullscreen-like and more responsive by giving a Fixed position to the vimeo-container, because I saw that there was padding at the bottom and we could see the white background of the body.
JSFIDDLE EXAMPLE
HTML:
<div class="vimeo-container">
<div class="overlay">
<div class="text-container">
<h1>Hello World!</h1>
</div>
</div>
<iframe src="https://player.vimeo.com/video/34905657?color=0fb0d4&title=0&byline=0&portrait=0" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p>Cowboy's Cat from Animade on Vimeo.</p>
</div>
CSS:
.vimeo-container {
position: fixed;
width: 100%;
height: 100%;
overflow: hidden;
max-width: 100%;
}
.vimeo-container .overlay{
position: absolute;
width: 100%;
height:100%;
background:#000;
opacity:0.5;
z-index:999;
}
.vimeo-container .overlay .text-container{
width:100%;
text-align:center;
}
.vimeo-container .overlay .text-container h1{
color:#FFF;
text-transform:uppercase;
}
.vimeo-container iframe,
.vimeo-container object,
.vimeo-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Since your video container already have position: relative, you can set position:absolute for you layer over video:
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
Here is a working fiddle exampple with your code: https://jsfiddle.net/Munja/d8w4o31k/
Also, you can take a look on this fiddle example with video playing in bg: https://jsfiddle.net/Munja/dpfzhw1v/ I used exactly this thing on one website I was working on some time ago.
I know there are a lot of questions out there regarding this topic, however I couldn't find a proper solution.
I have a #banner element on top of my site that is 710px high.
In this #banner I have my video that should always scale like "background-size:cover". It doesn't matter if the video is cut at the top or bottom, it should just always fill the #banner element.
#banner {
position:relative;
opacity:0;
height:710px;
width:100%;
overflow:hidden;
}
#banner .video {
position: absolute;
bottom: 50%;
right: 50%;
transform: translateX(-50%) translateY(-50%);
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
overflow: hidden;
}
I found this code right here but it doesn't properly work for me. The video does not resize when scaling the browser-window. For me this does not work.
Also I tried to use the covervid plugin that seems to work perfect for full-background sizes but not to fit it inside a banner with fixed height.
If I use this plugin and resize the window it jumps from width to height fitting, always setting the width or either height to auto.
Any idea how to do this via css or js?
Just remove the opacity from the banner and add max-height:100% to make sure that there's no vertical scroll
DEMO
html,
body {
margin: 0;
height: 100%;
}
#banner {
position: relative;
height: 710px;
border: 5px solid tomato;
overflow: hidden;
max-height: 100%;
box-sizing: border-box;
}
#banner .video {
min-width: 100%;
min-height: 100%;
}
<div id="banner">
<video class="video" autoplay>
<source src="http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4" type="video/mp4" />
</video>
</div>
I have responsive background and I want to have a YouTube video over that background(not in full width).
Here I have tried doing it.
http://jsfiddle.net/audetwebdesign/EGgaN/#run
HTML:
<div class="bg-image">
<img src="http://unplugged.ee/wp-content/uploads/2013/03/frank2.jpg">
<iframe width="560" height="315" src="//www.youtube.com/embed/R8wHnwfHscw" frameborder="0" allowfullscreen></iframe>
</div>
CSS:
.bg-image {
position: relative;
}
.bg-image img {
display: block;
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.bg-image iframe {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
Here's a jsfiddle forked from your fiddle that has the image as the background, as well as a responsive youtube video centered. Making the image have position:absolute takes it out of the normal flow and allows the embedded video to stay on top.
The trick for the responsive video code is to wrap the embedded video in a container with a max width, and then also adding in padding to keep the proper aspect ratio for the video. You then ensure that the iframe, object, and embded elements all fit at 100% of that container's width while also not getting any taller than the native size:
.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
overflow: hidden;
width: 100%;
max-width: 560px;
margin: 0 auto;
}
.video-container iframe,
.video-container object,
.video-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
max-height: 320px;
}
http://jsfiddle.net/QRkL9/
More about the above code - http://avexdesigns.com/responsive-youtube-embed/
braican is correct, but the 56.25% on the video container will leave lots of padding after your video. Just wrap everything inside another div with a max-height of 320px and overflow:hidden to hide the extra padding;