What I want to do is have an HTML5 video scale 100% width of the page, but maintain a fixed height of 650px.
The following code scales to maintain aspect ratio, which is not what I need:
<header>
<video width="100%" autoplay="autoplay">
<source src="video.webm" type="video/webm; codecs=vp8,vorbis">
</video>
</header>
I also tried a max-height="650px" but this only centres the video and leaves whitespace on either side.
What paypal does is scaling up the video according to the viewport. But they dont go mobile, and this is a problem.
So if you want to scale your video from small to big devices, you can put your video with the basic markup:
<video width="100%" height="auto">...
This is going to scale up your video. The problem is when you go to a small viewport. The video will scale down but can be too small, so you can define a min-height and use CSS transforms to scale up the video aspect:
video{
transform: scale(1.5);
-webkit-transform: scale(1.5);
}
With media queries you can define breakpoints and scale the video for those screens.
Also with some javascript you can also define a point of focus for your video (if some area of the video is more important).
Check this link for more details on that:
http://viget.com/extend/fullscreen-html5-video-with-css-transforms
I have achieved this by wrapping it into two containers with a set height (750px i.e.), backface-visibility: hidden; and overflow:hidden; - so the video gets larger in total but is being cropped off at the bottom (thanks to https://codepen.io/dudleystorey/pen/knqyK & http://fasett.no/ ):
.header {
height:750px;
overflow: hidden;
}
video {
display: block;
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%);
pointer-events: none;
overflow-y: hidden;
vertical-align: top;
}
.container_video {
-webkit-backface-visibility: hidden;
-webkit-background-size: cover;
-moz-background-size: cover;
-ms-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
width: 100%;
height: 100%;
z-index: 1;
position: relative;
}
<header class="header">
<div class="container_video">
<video preload="auto" autoplay loop muted poster="img/videobg.png" id="bgvid" src="//demosthenes.info/assets/videos/polina.mp4" ></video>
</div>
</header>
Related
I am trying to replace my website's header with a background video and am having trouble scaling it to desired size when on mobile. After messing around, I have found the following code to be working on all browsers on desktop when placed in the home section of my page.
<video playsinline autoplay muted loop poster="https://www.matelasdepot.net/video/video-restaurant.jpg" id="bgvid">
<source src="https://www.matelasdepot.net/video/video-restaurant.webm" type="video/webm">
<source src="https://www.matelasdepot.net/video/video-restaurant.mp4" type="video/mp4">
</video>
video {
position: fixed;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
max-width: none;
width: auto;
height: auto;
z-index: -100;
transform: translateX(-50%) translateY(-50%);
background-size: cover;
transition: 1s opacity;
overflow: hidden;
}
However, on mobile - the video doesn't scale. I'm not sure how to use #media with the video tag as every time I tried it didn't seem to impact the video at all. Does anybody have a clue on how I could fix this? Any help would be appreciated!
I have tried resizng the video with the following but it did not work
#media (max-width: 767px) {
video {
width: 300%;
height: 300%;
}
}
<div class="mission-statement">
<video style="min-height:100%" playsinline autoplay muted loop poster="{{ url_for('static',filename='images/cclc-background-image.png') }}" id="bgvid">
<source src="{{ url_for('static',filename='videos/cclc-clip2.mov') }}" type="video/webm">
</video>
</div>
#mission-statement {
margin-top: 0px;
margin-bottom: auto;
height: 100vh;
width: 100vw;
}
video#bgvid
{width: 100%; height: 100%; position: relative;}
Currently I have a video in the background of this div. However currently, when the screen is really wide, there is space on the left and right and when it is really narrow, there is space on the top and bottom.
Instead, I would like the video to zoom such that it is always touching all 4 sides. If the browser is narrow, it will be zoomed such that the left and right parts of the video are cut off. If the browser is really wide, it will be zoomed such that the top and bottom are cut off.
How can I accomplish this?
If you are only concerned with real modern browsers that conform to W3C standards (i.e. Not IE), use object-fit:cover. If IE is a must, there's a polyfill, but other than that, it would take too much effort and time to force a "browser" like IE to conform when it's obvious design is to conflict with everything that's sane and logical.
View in Full page mode
Demo
* {
margin: 0;
padding: 0;
border: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
width: 100%;
}
#mission-statement {
overflow: hidden;
position: fixed;
height: 100%;
width: 100%;
top: 0;
left: 0;
}
video#bgvid {
height: 100vh;
width: 100vw;
object-fit: cover;
overflow: hidden;
position: absolute;
bottom: 0;
right: 0;
}
<div class="mission-statement">
<video style="min-height:100%" playsinline autoplay muted loop poster="https://i.pinimg.com/originals/28/6c/00/286c004a0cc4a49a5e6985b0e0812923.gif" id="bgvid">
<source src="http://media6000.dropshots.com/photos/1381926/20170326/005609.mp4" type="video/mp4">
</video>
</div>
Try this:
video#bgvid {
/* 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've been trying for hours how to fix a bug that is happening only on chrome.
There are 2 layers in a wrapper, which are:
Parallax background
Normal content scrolled
i've been doing parallax effect by using translateZ and scale rules, everything works fine on firefox.. but for some reason which i don't know, on chrome it makes the parent wrapper to take a huge size to fit with the scale from the parallax background.
many posts say that this issue can be fixed by adding translateZ(0) or z-index: 0 to the wrapper but yet it doesn't fix my issue. So the code on CSS for parallax looks like this:
#parallax {
perspective: 1px;
height: 100vh;
overflow-x: hidden;
overflow-y: auto;
}
.parallax__layer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.parallax__layer--base {
transform: translateZ(0);
}
#parallax__layer--back {
transform: translateZ(-50px) scale(56);
background: url("/assets/images/background.jpg");
background-repeat: no-repeat;
background-size: 100% 100%;
background-attachment: fixed;
background-position: center;
scroll-behavior: smooth;
}
HTML where parallax should be positioned:
<body>
<div id="parallax">
<div id="parallax__layer--back" class="parallax__layer "></div>
<div class="parallax__layer parallax__layer--base">
<!-- Base Content -->
</div>
</div>
</body>
I want to make an html5 video fit any size of the screen, if it's a iMac huge screen or if it's a phone, I want it to be responsive.
1) If it's a 4:3 monitor, it should show blank spaces (black bars) above and below video
2) If it's a super wide screen it should fit the height but show blank spaces left and right
3) Same with mobile, if it's portrait or landscape position
This is my HTML
<div class="video-container"> <!-- background darkener -->
<video controls>
<source src="img/vid.mp4" type="video/mp4">
</video>
</div>
CSS:
.video-container {
position: fixed;
top: 0; left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.9);
}
.video-container video {
/* Here is what I want to know how to make it fit the way we want */
}
I don't mind using jQuery if more real time calculations are needed!
Thanks beforehand
Try this, works for me
.video-container video {
position: absolute;
top:0;
right:0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
background-size: 100% 100%;
background-image: url('your-video-poster.jpg');
background-position: center center;
background-size: contain;
object-fit: cover;
z-index: 100;
}
I am looking to make my video background like this:
http://www.teektak.com/
The issue I'm having is that my video is responsive, but it is fixed to the left. I can't figure out for the life of me how to make it so that it centers horizontally to the window when adjusted.
Here is a link to the test site to see what I am talking about: https://robotplaytime.paperplane.io/
HTML
<body>
<video poster="images/robotPlaytimeVideo.png" id="bgvid" autoplay loop muted>
<source src="images/robotPlaytimeVideo.mp4" type="video/mp4">
</video>
</body>
CSS
html,
body {
height: 100%;
width: 100%;
overflow: hidden;
}
video {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
min-width: 100%;
min-height: 100%;
z-index: -100;
background: url(../images/robotPlaytimeVideo.png) no-repeat;
background-size: cover;
}
Add these CSS rules to your body (the video's parent container):
text-align: center; /* ensures the image is always in the h-middle */
overflow: hidden; /* hide the cropped portion */
Add these CSS rules to your video:
display: inline-block;
position: relative; /* allows repositioning */
left: 100%; /* move the whole width of the image to the right */
margin-left: -200%; /* magic! */
Most of this was pulled directly from Bryce Hanscomb's answer to another similar question: How to center crop an image (<img>) in fluid width container
Here's a jsfiddle just in case:
http://jsfiddle.net/pLj0gcpu/
(Note that the markup and styles in this fiddle were pulled from your given URL)
To get the video to take the full size of the screen:
video {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
height: 100%;
width: 100%;
}
If you wanna center something horizontally responsively, then do
left: 50%;
transform: translateX(-50%);
Note, you will need to set a "position" as well