Html & Css: Video backgroud adapt monitor size - html

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!

Related

I want to make the background video full screen in css

I'm adding a video to my project, but no matter what I do, its size doesn't exceed certain limits. I want to make the video full screen
Here is my css code
#myvideo{
position: fixed;
right: 0;
bottom: 0;
min-height: 100%;
min-width: 100%;
}
#myvideo{
position: fixed;
right: 0;
bottom: 0;
min-height: 100%;
min-width: 100%;
}
just on your html make sure the video id is same on css myvideo not myVideo:
<body> <video autoplay muted loop id="myvideo"> <source src="walk.mp4" type="video/mp4"> </video>

How do i make a video fully take up the screen width html?

So, I was trying to make a video take up the whole size of the screen but have failed multiple times. The best try to solve it was having the following code:
video {
position: absolute;
top: 0;
left: 0;
z-index: -1;
max-height: 100%;
min-width: 100%;
}
<video autoplay="" loop="" muted>
<source src="highway-loop.mp4" type="video/mp4" />
</video>
but then, also there is a little border and it's not full screen like this
https://nothing-to-see-he.re/57mz2UVuG
Any idea how i can fix it?
video {
position: absolute;
top: 0;
left: 0;
z-index: 1;
max-height: 100%;
min-width: 100%;
}
<video autoplay="" loop="" muted>
<source src="https://i.imgur.com/9f6mEiR.mp4" type="video/mp4" />
</video>
First you have z-index:-1 (which makes ur video go behind the screen/element) I changed it to z-index:1.
Click "Run this code" button to see that it works now. It also take full width and height of the div it is inside by default. Since in this current example nothing is stoping it, it does goes full size. Click "Full page" to confirm.
Thirdly the https://nothing-to-see-he.re/57mz2UVuG looks like the borders are from the video itself and not from html/css.
Use
video {
position: absolute;
top: 0;
left: 0;
z-index: -1;
min-width: 100vw;
min-height: 100vh;
}
because the max-height doesn't allow the width to increase.
I had the same Problem 2 Months ago. But i figured it out :D
Index.html
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
...
<video autoplay muted loop id="video">
<source src="video2.mp4" type="video/mp4">
</video>
...
Style.css
body {
margin: 0;
padding: 0;
background: #333333;
}
#video {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
I hope this might help you :D
Wrap your video in a container. And do something like this.
.container {
position: absolute;
top: 0;
left: 0;
right: 0;
width: 100%;
height: 100vh;
background-color: coral;
}
video {
position: relative;
width: 100%;
height: 100%;
}
<div class="container">
<video autoplay="" loop="" muted>
<source src="https://i.imgur.com/9f6mEiR.mp4" type="video/mp4" />
</video>
</div>

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;
}

Chromium Ignoring z-Index

I'm unable to get Chromium to allow me to overlay text or images over an inline video. I've tried setting the z-index (both in CSS and JS); I've tried adjusting the z-index after the video has already started playing, but no luck.
HTML:
<span id="text">test</span>
<video playsinline autoplay muted loop>
<source src="https://rawgit.com/bower-media-samples/big-buck-bunny-480p-30s/master/video.mp4" type="video/mp4"></source>
</video>
CSS:
video {
width: 300px;
height: 300px;
object-fit: cover;
position: fixed;
z-index: -1;
top: 50px;
left: 0;
}
#text {
color: red;
font-size: 100px;
position: fixed;
z-index: 9999;
}
I have a jsfiddle that works correctly in FF/Chrome/Safari; it's just not working on Chromium... the text stays behind the video.
Is there any way I can overlay over this inline video?

Video as background parallax CSS

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.