How to make my video responsive in website ? [html] - html

Is there any way to make a video in <video> tag mobile responsive ?
<video autoplay muted loop id="myVideo">
<source src="rick.mp4" type="video/mp4">
</video>
<style>
#myVideo {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
</style>

Please check, I have did Video responsive in following ways.
1st Option You can use media Queries
<video autoplay muted loop id="myVideo">
<source src="https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" type="video/mp4">
</video>
<style>
#myVideo {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
max-height: 100%;
}
#media(max-width: 640px){
#myVideo {
width: 100%;
}
}
</style>
2nd Option set width: 100% instead of min-width: 100%
<video autoplay muted loop id="myVideo">
<source src="https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" type="video/mp4">
</video>
<style>
#myVideo {
position: fixed;
right: 0;
bottom: 0;
width: 100%;
max-height: 100%;
}
</style>
3rd Option Add wrapper for video tag and handle the responsive
<div class="video-Wrapper">
<video autoplay muted loop id="myVideo">
<source src="https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" type="video/mp4">
</video>
</div>
<style>
.video-Wrapper {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #000;
}
#myVideo {
position: absolute;
right: 0;
bottom: 0;
width: 100%;
max-height: 100%;
}
</style>

The most easiest way is to give your video width as a percentage. This means the width of the video will be the % of the container it is in.
Please check the code below. (I have used a division instead of a video)
<div>12345</div>
<style>
div{
width:80%;
height:300px;
background:#dadada;
}
</style>
If you want dfferent css properties at different width o the body then you should use the #media query. Check this for more on #media queries. https://www.w3schools.com/cssref/css3_pr_mediaquery.asp

Related

Set a maximum size to the video size ratio

Set a maximum size to the video size ratio
.videoWrapper {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
height: 0;
max-width: 1024px;
max-height: 576px;
}
.videoWrapper video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
max-width: 1024px;
max-height: 576px;
}
And HTML code
<div class="videoWrapper">
<video class="aspect-ratio-box" autoplay>
<source src="../../../assets/original.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
Here the result : https://prnt.sc/s6y3no
The width size is correctly limited to 1024px. The problem is that the height is not limited. It does not allow to put the paragraph below the video.
Why is he ignoring my css rules? How can I overcome this problem
Thanks for helping
I found the solution.
.video {
object-fit: cover;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
.video-frame {
position: relative;
padding-bottom: 56.25%;
display: block;
overflow: hidden;
}
.video-container {
max-width: 1024px;
}
And HTML
<div class="video-container">
<div class="video-frame">
<video class="video" autoplay>
<source src="../../../assets/original.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</div>

CSS code with background video under header and body content

At the top of my page is a header, and is pulled in from a different file/folder using php.
I would like to have the background video fully covered under my content body and under my header. But whenever I put it, then it is under my content only and the header is disappearing for some reason. Also, when I put it for header only, then I will get it at the top only and the body will be empty with my normal content but without the background video.
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
font-size: 17px;
}
#myVideo {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
<video autoplay muted loop id="myVideo">
<source src="https://www.belloo.date/upgrade/themes/landing2/images/bg.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
I don't know if is that what you are trying to achieve, but you can try add a z-index negative and do some css ajusts.
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
font-size: 17px;
}
#myVideo {
position: fixed;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
transform: translateX(-50%) translateY(-50%);
}
<video autoplay muted loop id="myVideo">
<source src="https://www.belloo.date/upgrade/themes/landing2/images/bg.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
<h1>Test</h1>
I do not know exactly what you mean, but maybe this will help you here.
I defined the header in css.
header {
position: fixed;
top:0px;
left: 0px;
right:0px;
min-width: 100%;
z-index: 1;
background-color: #fff;
padding: 10px;
}
and put the header tag
<header>My Header</header>
full html page
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
font-size: 17px;
}
header {
position: fixed;
top:0px;
left: 0px;
right:0px;
min-width: 100%;
z-index: 1;
background-color: #fff;
padding: 10px;
}
#myVideo {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
<html>
<head>
</head>
<body>
<header>My Header</header>
<video autoplay muted loop id="myVideo">
<source src="https://www.belloo.date/upgrade/themes/landing2/images/bg.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
</body>
</html>

Place div over part of video background, scalable

I have .mp4 as background of my site. The video is containing some non-moving elements. Let's say a square.
I want to place a div over this square and let it scale with the video if the window resizes.
I am testing, but the main problem is that the aspect ratio of the div is changing when resizing the window.
jsfiddle with example video:
https://jsfiddle.net/xhrub7so/6/
HTML
<div class="wrapper">
<div class="fullscreen-bg">
<video loop muted autoplay poster="img/videoframe.jpg" class="fullscreen-bg__video">
<source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
</video>
</div>
<div class="url_1">
test
</div>
</div>
CSS
.fullscreen-bg {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
z-index: -100;
}
.fullscreen-bg__video {
position: absolute;
top: 0;
left: 0;
width: 100%;
}
.url_1
{
position: absolute;
margin-top:20%;
margin-left:20%;
width: 50%;
height:30%;
background-color: #cccccc;
display:block;
}
.wrapper{
width:100%;
height:100%;
}
Thanks for the help.

Video won't fill the width of the container

As you can see in the image I provided the video is not full width, I want it to fit the rest of the container. Can anyone tell me what I'm doing wrong, here is the image:
Image of the div and video
The code:
HTML
<section class="content-2">
<div class="fullscreen_bg">
<video loop muted autoplay poster="img/videoframe.jpg" class="fullscreen-bg_video">
<source src="images/Ajvar.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video></div>
</section>
CSS
.content-2 {
height: 350px;
overflow: hidden; }
.fullscreen-bg {
max-height:350px;
width: 100%;
height: 100%;
position: relative;
padding:0;
margin:0;
left: 0px;
top: 0px;
z-index: -1000;
overflow:hidden;}
.fullscreen-bg__video {
position: absolute;
top: 0;
left: 0;
min-height: 100%;
z-index: -100;
background-size: cover;
overflow: hidden;}
#media (min-aspect-ratio: 16/9) {
.fullscreen-bg__video {
height: 300%;
top: -100%;
}
}
#media (max-aspect-ratio: 16/9) {
.fullscreen-bg__video {
width: 300%;
left: -100%;
}
}
Try width attribute for video tag:
<video loop muted autoplay poster="img/videoframe.jpg" class="fullscreen-bg_video" width="350" height="350">
<source src="images/Ajvar.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>

Html and Hmtl5 Video

I have my video playing in the background but how do I add images over the video? I kind of want it like this image over videoMy video
body, html {
margin: 0;
padding:0;
}
video{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: 1;
}
<div class="container" >
<video poster="Sample.jpg" autoplay="true" loop id="video">
<source src="Burning.mp4" type="video/mp4">
<source src="Burning.webm" type="video/webm">
</video>
You can always build HTML structure for the images as shown in the images and use the video as background of it using some video player plugin like (http://vodkabears.github.io/vide/).
body, html {
margin: 0;
padding:0;}
.container{ width: 70%; background: #000; margin: auto; }
.vid{float: left; width: 100%; }
video{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -1;
}
<div class="container" >
<video poster="Sample.jpg" autoplay="true" loop id="video">
<source src="1.mp4" type="video/mp4">
<source src="1.webm" type="video/webm">
</video>
<img src="http://via.placeholder.com/350x150">
</div>
container centered and image placed on top of the video