Full page cropped video in HTML5 - no jquery - html

I'm trying to add a video in the background of my website. I want to do this without any javascript to optimize the loading time.
So far, I used this code:
HTML:
<video id="video_background" preload="auto" autoplay="true" loop="loop" muted="muted" volume="0" poster="img/video-poster.jpg" >
<img src="img/video-poster.jpg" alt=""/>
<source type="video/mp4" src="video/video.mp4"/>
<source type="video/ogg" src="video/video.ogv"/>
</video>
CSS:
#video_background {
position: absolute;
bottom: 0px;
right: 0px;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -1000;
overflow: hidden
}
The problem is that my video has a panoramic format (16/9) with black margins on top and bottom. Obviously I don't want them to appear on the screen. So with this code, the blacks margin appear on the bottom of the page.
How can I make sure the black margins are cropped and still have a responsive display?
Thanks

There may be a better option out there but I find this to be an elegant solution in my eyes.
I gave the video #video-background a scale(1.09) which would zoom the video in ever so slightly to remove the borders.
I also added this to the html and body to disable the video from going under the fold. This is optional but you will have the bottom border without it.
html, body {
height: 100%;
width: 100%;
position: fixed;
margin: 0;
padding: 0;
}
The css for your video,
#video-background {
position: absolute;
top: 0px;
right: 0px;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -1000;
overflow: hidden;
transform: scale(1.09);
-webkit-transform: scale(1.09);
-moz-transform: scale(1.09);
-o-transform: scale(1.09);
}
Finally, here is the JSFIDDLE to show how it looks. In the url, remove /show to see the code.

Related

Using and MP4 as a div background and fill the space as the window is resized

I have tried using the tag but when the window is resize I need the video to fill the space as the window is resized. At the largest scale it fills the space and as is shrinks it starts to add a lot of white space at the top and bottom.
HTML
<video playsinline autoplay muted loop poster="images/user_item.mp4" class="w-100" style="">
<source src="images/user_item.mp4" type="video/mp4">
</video>
CSS
video {
position: absolute;
min-width: 100%;
min-height: 100%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
height: 300px;
border-radius: 5px 0 0 5px;
}
Is it possible to play the video in a canvas and resize the canvas and have it fill the entire space provided?
No need for a canvas, just use CSS. In particular here you want the object-fit property.
By default for video it's set to contains, meaning it will set the size of the media to the smallest side and add borders to the largest, keeping the aspect-ratio of the media.
From your description it's quite unclear if you want the cover which keeps aspect-ratio but cuts the media,
video {
position: absolute;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
object-fit: cover;
}
<video src="https://upload.wikimedia.org/wikipedia/commons/a/a4/BBH_gravitational_lensing_of_gw150914.webm" autoplay loop muted></video>
or fill, which just stretches/shrinkes the media.
video {
position: absolute;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
object-fit: fill;
}
<video src="https://upload.wikimedia.org/wikipedia/commons/a/a4/BBH_gravitational_lensing_of_gw150914.webm" autoplay loop muted></video>
And for future readers, note that this CSS property can also be set to <canvas>.

How to add a small stripe video background using html like kidscodeacademy.com?

I need to add a full screen video as background but in a html div section on home page. This website has nice stripe video. I exactly like that video. How can I add such effect over the video.
Note: I have web-m format video file.
Video Background , Put your content inside the container.
https://jsfiddle.net/ashwinshenoy/rh7n5d0g/1/
Hope this Helps buddy!
<div class="video_div">
<video class="video is-playing" autoplay="" muted="" loop="" poster="assets/video/thumb.jpg">
<source src="http://ak3.picdn.net/shutterstock/videos/5949803/preview/stock-footage-little-children-playing-football-at-school-k.mp4" type="video/mp4">
</video><!--video tag end-->
<div class="video-overlay" style="background-image: url("https://d3k5xyayaartr5.cloudfront.net/_assets/pattern-overlays/patterns/black-dots.png");"></div>
<div class="container">
<!--your content here-->
</div><!--container end-->
</div><!--video_div end-->
<style>
// Video Div
.video_div {
overflow: hidden;
padding: 230px 0 0;
position: relative;
width: 100%;
height: 87vh;
}
#media screen and (max-width: 767px) {
.video_div {
padding: 230px 0;
width: 100%;
}
}
.video_div video {
position: absolute;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%,-50%);
-moz-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
z-index: -200;
}
.video-overlay {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
pointer-events: none;
opacity: .5;
background-repeat: repeat;
}
// Video Div End
</style>
I do not know about your specific needs , but for a basic understanding of this header fullscreen background video I can give you a link where you can learn how to make it.
https://www.youtube.com/watch?v=O_Bw1_0u1P8
Please let us know , if there is any problem .

Fullscreen video bg in div that behaves like the div is its alpha?

The effect I'm going for here is to have a main full-screen video as the background and on top of that I want to have a div that centered and have it look like the background video gets blurred by this div, and to do this I'm trying to use another version of the video that is pre-blurred and on-top of the bg video but I only want this video to be visible where the div is, and the div is moving dynamically independent of the background, so would be like the div were the alpha channel for the blurred video, hopes this makes sense.
Here an image of the look I'm trying for:
and here is as jsfiddle of what I have so far:
JSFIDDLE
.::CODE::.
HTML:
<div id="wrapper">
<div id="main"></div>
</div>
<video autoplay loop muted id="bgvid">
<source src="http://www.patan77.com/screenshot/test_bg_vid.mp4" type="video/mp4">
</video>
<video autoplay loop muted id="bgvid_blur">
<source src="http://www.patan77.com/screenshot/test_bg_vid_blur.mp4" type="video/mp4">
</video>
CSS:
body { margin: 0; padding: 0; }
#main{
position:absolute;
width: 100%;
height: 500px;
background: rgba(0, 0, 0, .25);
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
video#bgvid {
position: fixed;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
video#bgvid_blur {
position: fixed;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -99;
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
UPDATE:
Experimented with clip path a bit, and its closer to what I want (but still not really), but noticed another problem the videos (blur and the not blurred version) don't play in sync, and don't know how I would make sure they are always in sync, damn this turned out to be a bit harder then I initially thought it would be.
JSFIDDLE_v02

Video height and width for responsive website

I am using the video HTML5 tag on a responsive website. I set the height and width to 100% and it works fine except in the mobile version where it's destroying the layout.
URL: omob-2.myshopify.com
<div style="height: 100%; width: 100%;">
<video width="100%" height="100%" autoplay>
<source src="intro_12_07_14.mp4" type="video/mp4">
</video>
</div>
Any ideas?
You can use both the max-width property or object-fit property to achieve this. See references: Using the object-fit property and Using the max-width property with fill-available
/* Using fill-available on the max-width property */
/* A box you would like to place the video in*/
.wrapper {
width: 600px
height: 300px;
}
/* The video */
.wrapper_video > video {
width: 100%;
max-width: -webkit-fill-available;
max-width: fill-available;
}
/* The object-fit property defines how an element responds to the height
and width of its content box.*/
/* A box you would like to place the video in*/
.wrapper {
width: 600px
height: 300px;
}
/* The video */
.wrapper_video > video {
width: 100%;
height: 100%;
object-fit: cover;
}
On devices that don't support the video tag you would show a image instead. There is a answer for this here How can I display an image if browser does not support HTML5's <video> tag
Edit: set the width and height in the css styles instead of the video tag. Set the width only, so to keep dimensional proportion, like this.
video {
width: 100%;
height: auto !important;
}
Use the CSS3 transform translate(-50%, -50%) to make the video in the center of the page:
Html Code
<div class="video-container">
<video autoplay loop="true" width="1280" height="720">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
</div>
CSS Code
.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%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
body {
background: #000;
color: #fff;
font-family: 'Oxygen', sans-serif;
}
See here the demo.

Video tag to fill 100% div regardless of ratios

I am tying to have a video tag to fill 100% of a div:
a) it doesn't need to keep the ratios(otherwise we need to use the overflow:none);
b) fill a div, not the whole background;
c) it would be a plus to be responsible. Now it is as long as you re-size window diagonally. Keeping height and re-sizing horizontally cuts the video.
I have tried dozens if not hundreds of alternative, and all of them keep the initial video ratio.
it works in the fidlle .... maybe because the screen is small, maybe because fiddle is a better browser...
<body>
<div class="wrapper">
<div class="header">
.....
</div>
<div class="out-video">
<video autoplay loop poster="mel.jpg" id="bgvid" width="100%" height="100%">
<source src="http://www.mysite.braaasil.com/video/mel.webm" type="video/webm">
<source src="http://www.mysite.braaasil.com/video/mel.mp4" type="video/mp4">
</video>
</div>
</div>
The site is here but as I try the solutions, it will change... There is a right and left sidebar empty. I would like the video to fill the whole width. When it covers the div, the height change and the video does not show in full. I would like something like the background-size 100% 100% that stretches the images to the end of the div, but it does not work for video.
Thank you for any suggestion in advance.
PS. It seems that android family does not play the video!
l
Use object-fit css property, though there is no support for IE, but it's still quite reasonable to be used for <video>, <img> tags.
Check CanIUse for Browser Support, and CSS-Tricks for usage.
Example:
/** If parent has some defined width/height */
.video-element {
width: 100%;
height: 100%;
object-fit: cover;
}
You can use a solution like this one. Ratio dont change, but you may lose the right part of the video.
video#bgvid {
position: absolute;
z-index: 0;
background: url(mel.jpg) no-repeat;
background-size: 100% 100%;
top: 0px;
left: 0px; /* fixed to left. Replace it by right if you want.*/
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
}
The video will be fix to top left corner. If you want to improve it, I think you will need some JavaScript.
Edit :
Just a find a solution with JQuery who can fit your need : simulate background-size:cover on <video> or <img>
Demo
Simple CSS inheit
video {
width: inherit;
height: inherit;
}
div {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: black;
}
Try this
HTML:
<div id="MainBanner">
<video autoplay muted loop>
<source src="something-nice.mp4" type="video/mp4">
</video>
<div class="content">
<h1>Heading</h1>
<p>Some Content</p>
</div>
</div>
Less:
#MainBanner {
position: relative;
height: 100vh;
overflow: hidden;
video {
background: url(cover.jpg) no-repeat;
top: 0px;
left: 0px;
min-width: 100%;
min-height: 100%;
}
.content {
position: absolute;
padding: 20px;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
color: #f1f1f1;
width: 100%;
}
}