Video as background parallax CSS - html

I'm more backend guy than frontend, so if you consider my question as dummy, sorry for that, but I couldn't find answer :)
My aim is to have background video with parallax using CSS. In general I did manage to do that, but result is not good enough. Because of some reason, video which is in background is under all sections, instead of being in just one section where it supposed to be...
HTML:
<div class="fullScreenPhoto"></div>
<div class="video-container">
<video autoplay poster="" class="video-parallax" loop muted>
<source src="https://showbox-tr.dropbox.com/transcode_video/t/1qz2fy47wt9ay7i/header_background.mp4" type="video/webm">
<source src="https://showbox-tr.dropbox.com/transcode_video/t/1qz2fy47wt9ay7i/header_background.mp4" type="video/mp4">
</video>
</div>
<div class="fullScreenPhoto2"></div>
<div class="fullScreenPhoto3"></div>
CSS:
body{
margin: 0;
padding:0
}
.fullScreenPhoto{
width: 100%;
margin:0;
height:300px;
background-color: red;
}
.fullScreenPhoto2{
width: 100%;
height:300px;
margin:0;
background-color: green;
}
.fullScreenPhoto3{
width: 100%;
margin:0;
height:300px;
background-color: yellow;
}
video {
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
transform: translateX(-50%) translateY(-50%);
background-size: cover;
transition: 1s opacity;
}
.video-container {
height: 600px;
}
.video-parallax {
-webkit-transition-position: fixed;
position: fixed;
}
Here you can fiddle:
Fiddle
where I've duplicated my issue. If you will hide one section, or change z-index for higher, you are able to see, that video is all over the page...
BTW. I know about plugin jQuery -> https://github.com/linnett/backgroundVideo, but I would like to use just CSS.

You can easily do this as you do with image parallax.
The HTML:
<div class="ParallaxVideo">
<video autoplay muted loop>
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
<source src="http://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
</video>
<h1>Video Background</h1>
</div>
The CSS
.ParallaxVideo{
height: 300px;
padding-bottom: 50px;
padding-top: 50px;
}
.ParallaxVideo video{
min-width: 100%;
position: fixed;
top:0;
z-index: -999;
}
.ParallaxVideo h1 {
color: #fff;
font-size: 76px;
font-weight: 700;
text-align: center;
text-transform: uppercase;
}
You can also take a look this tutorial for more details:
https://codeconvey.com/video-parallax-background-using-css3/
Here is demo version:
http://codeconvey.com/Tutorials/VideoParallaxBackground/

If you want video to be background only for this one div then you couldn't have parallax effect, because then you need remove position: fixed for .video-parallax (so all styles for this class as I see) and change styles for video to that:
video {
margin:0 auto;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
background-size: cover;
transition: 1s opacity;
}

You need to set a css height for the video element, or on the element itself like <video height="400">. Updated Fiddle.

For this purpose I am using Materialize CSS. It is straightforward. We want a video as background parallax CSS.
HTML WITH MATERIALIZE CSS
<style>
#anyvideo{
position: absolute;
right: 0;
bottom: 0;
min-width: 10%;
min-height: 100%;
}
</style>
<div class="video-container parallax-container">
<video autoplay muted loop id="anyvideo">
<source src="somevideo.mp4" type="video/mp4">
</video>
</div>
We can also make our video responsive i.e. adjust to screen size accordingly.
<div class="video-container parallax-container">
<video autoplay muted loop id="anyvideo" class="responsive-video">
<source src="somevideo.mp4" type="video/mp4">
</video>
</div>
In the above code only the class="responsive-video" has been added and that makes the video responsive.

Related

creating a video container that covers the whole screen

i want to create a video container that covers the whole screen
and the video inside the container covers the whole container and doesn't overflow means container adapts the whole screen size.
and is responsive accordingly.
currently the video is taking its full height..i don't want that
i want its height to be limited to the screen size and there is no scroll.
my html code is
<div class="video-container">
<div class="video-wrapper">
<video autoplay controls>
<source src="../../assets/movies/joker.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>
</div>
</div>
my css code is :
.video-container {
display: block;
max-width: 100%;
min-width: 200px;
}
.video-wrapper {
background: #000;
border-radius: inherit;
overflow: hidden;
position: relative;
z-index: 0;
}
.video-container video {
border-radius: inherit;
height: auto;
vertical-align: middle;
width: 100%;
}
video {
max-width: 100%;
object-fit: contain;
}
please help me with this problem..thanks in advance.
CSS:
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
font-size: 17px;
}
video {
position: fixed;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
}
HTML:
<body>
<script src="./index.js"></script>
<video autoplay controls>
<source src="../../assets/movies/joker.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
</body>
A meta tag like this helps:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
You need to change your width and height, CSS features the possibility for view height and view width, so it fits the screen. As already mentioned above:
.video-wrapper{
height: 100vh;
width: 100vh;
}

How do I fit a video to the background of a web page using HTML/CSS and Bootstrap?

I'm trying to get the video to fit the screen. Currently it is massive and I can't figure out how to make the scroll bars disappear. Object-fit doesn't look like it's working as it is supposed to. Also, when I make the screen smaller obviously I want the video to scale with it.
HTML
<div class="video-background">
<video autoplay muted loop>
<source src="img/cocktail_pour.mp4" type="video/mp4">
</video>
</div>
CSS
body {
margin:0;
padding:0;
}
.video-background {
width:100%;
height:100vh;
overflow:hidden;
display:flex;
justify-content:center;
align-items:center;
}
.video-background video{
position:absolute;
top:0;
left:0;
object-fit:cover;
}
Bootstrap 5 (update 2019)
Use helper classes to eliminate the need for a lot of extra CSS...
<header>
<div class="position-absolute top-50 w-100">
<h1 class="text-white text-center">Overlay Text</h1>
</div>
<video autoplay loop id="video-background" class="position-absolute end-0 bottom-0 h-auto w-auto">
<source src="https://www.w3schools.com/howto/rain.mp4" type="video/mp4"> Your brower is old
</video>
</header>
Bootstrap 5 full screen video
Bootstrap 4 (original answer)
You can use absolute position and then overlay whatever you want on the video so it remains as a background...
<header>
<div class="overlay">
Text
</div>
<video id="video-background">
...
</video>
</header>
#video-background {
position: absolute;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
}
.overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color:rgba(0,0,0,0.5);
}
Demo: https://codeply.com/p/aUjjU2uIXH
This works across most browsers:
HTML:
<div class="video-background">
<video autoplay muted loop class="video">
<source src="https://www.w3schools.com/howto/rain.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
</div>
<div class="content">
<!-- CONTENT GOES HERE -->
</div>
CSS:
.video { /* This is to make the video appear behind everything else */
position: fixed;
z-index: -1000; /* Z-Index is -1000 just to be safe */
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
.content { /* This is for the content */
position: fixed;
z-index: 1; /* This can be set to any number greater than -1000. */
bottom: 0;
background: rgba(0, 0, 0, 0.5);
color: #f1f1f1;
width: 100%;
padding: 20px;
}

Html & Css: Video backgroud adapt monitor size

i need to use a mp4 video as background.
I would like the video to adapt to the size of the screen and not overlap with what is underneath.
I write:
<video autoplay loop muted poster="<?php echo $wo['config']['theme_url'];?>/img/1-s.png" id="bgvid">
<!-- MP4 must be first for iPad! -->
<source src="<?php echo $wo['config']['theme_url'];?>/video/1bis.mp4" type="video/mp4" /><!-- Safari / iOS video -->
</video>
And my css is:
video#bgvid {
position: absolute; right: 0; bottom: 0;
min-width: 100%; min-height: 100%;
width: auto; height: auto; z-index: -100;
background-size: cover;
z-index: 0;
}
by assigning "top: 0", I would like the video to be displayed with:
height: 100vh;
overflow: hidden;
Hi Matteo is better positioning 50% left and top and after traslate the video to center it inside the page.
With z-index you can use negative number. If the video is used for background, add z-index: -1. In this way the other object stay over the video.
body {
padding:0;
}
video {
position: fixed;
top:50%;
left:50%;
transform:translate(-50%,-50%);
min-height:100%;
min-width:100%;
z-index:-1;
}
<video autoplay loop>
<source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4">
</video>
<h1>
PAGE TITLE
</h1>
I found this https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_fullscreen_video that I think is the best solution for your case.
The key of your problem is the position of the video.
#myVideo {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
Hope it helps!

container width error in bootstrap custom css

I want to make background video for the website. Whatever I am doing there is a gap in the top and left sides. I changed the width left position anyway the error still is same. Please find the print screen from the website. I also attached my CSS and HTML code. Thank you for reading.
CSS:
header-container {
width: 90%;
height: 900px;
border-left: 1%;
border-right: none;
position: relative;
padding: 20px;
}
.video-container {
top: 0%;
left: 0%;
height: 100%;
width: 100%;
overflow: hidden;
}
video {
position: absolute;
z-index: -1;
width: 100%;
}
HTML:
<div class="header-container">
<div class="video-container">
<video preload="true" autoplay = "autoplay" loop = "loop" muted>
<source src="video/test.mp4" type="video/mp4" >
</video>
</div>
</div>
https://ibb.co/incNY5
You have padding in heading-container. Set it 0px.

Make a video be full screen size CSS

I'm using the videojs.com video player and it works great the only problem is that I want the video player to be the full-screen size instead of using pixels like for example if you are on a smaller screen the video player looks messed up.
I tried to use 100% instead of px but it also messed up a lot.
Is there some other way I can make it fit the whole screen automatically?
<video id="player" class="video-js vjs-default-skin" controls autplay="true" preload="auto" width="1880px" height="980px"
poster="FF7.png"
data-setup="{}">
<source src="FF7.mp4" type='video/mp4' />
<track kind="subtitles" src="FF7.vtt" srclang="en" label="Svenska"></track>
</video>
Check the Codepen here
video {
position: fixed;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
transform: translateX(-50%) translateY(-50%);
background: url('//demosthenes.info/assets/images/polina.jpg') no-repeat;
background-size: cover;
transition: 1s opacity;
}
You can use a parent div container for your video, so it acts like a cross browser anchor for your video. Also you can use the media query min-aspect-ratio and max-aspect-ratio.
Codepen example with editor:
http://codepen.io/jonathan/pen/bEbdmz/?editors=110
Codepen example in fullscreen mode:
http://codepen.io/jonathan/full/bEbdmz/
The HTML
<div id="video-wrapper">
<video id="player" class="video-js vjs-default-skin" controls autplay="true" preload="auto" width="1880px" height="980px" poster="FF7.png" data-setup="{}">
<source src="FF7.mp4" type='video/mp4' />
<track kind="subtitles" src="FF7.vtt" srclang="en" label="Svenska"></track>
</video>
</div>
The CSS:
html, body {
height:100%;
}
body {
margin:0;
padding:0;
}
#video-wrapper {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
}
#video-wrapper > #player {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
cursor:pointer;
}
#media (min-aspect-ratio: 16/9) {
#video-wrapper > #player {
height: 300%;
top: -100%;
}
}
#media (max-aspect-ratio: 16/9) {
#video-wrapper > #player {
width: 300%;
left: -100%;
}
}
And if you want a JavaScript fullscreen solution you could use some of the following:
http://vodkabears.github.io/vide/
http://dfcb.github.com/BigVideo.js/
http://syddev.com/jquery.videoBG/