Fill space remaining under a video - html

I've got a very simple page with two divs. One of these div display a video with a 16:9 aspect ratio and there's another div under it. I would like this second div to fit the remaining space between the bottom of the video and the bottom of the container, knowing that this container is not fix.
But right now, I don't get a way to do it.
https://jsfiddle.net/kmfvh8rg/1/
<div id="pbzone">
<div id="pgzone">
<video preload="auto" autoplay="true" width="100%" src="http://www.w3schools.com/html/mov_bbb.mp4" id="player"/>
</div>
<div id="ppzone">
</div>
</div>

There are two possibilities to achieve what you want:
First one is by using absolute positioning as you tried, and the div you want green to be a layer under the video (using z-index property).
The problem in your case is that your div does not have any width. Add left: 0; and right: 0; or simply width: 100%; to #ppzone{ } css.
You should also had close </video> tag, and add position: relative; to container: #pgzone. Without position: relative; added to container, the div with position: absolute; referenced to body instead to the parent you actually wanted to refer.
This CSS case is exemplified below:
#pgzone{
position: relative;
border-style: solid;
width: 500px;
height: 600px;
border-width: 1px;
}
#pgzone video{
position: relative;
z-index: 10;
}
#pbzone{
height: 80%;
position: relative;
background-color: #0e0e0e;
}
#ppzone{
position: absolute;
z-index: 5;
bottom: 0;
top: 39.25%;
background-color: green;
left:0;
right: 0;
}
<div id="pgzone">
<video preload="auto" autoplay="true" width="100%" src="http://www.w3schools.com/html/mov_bbb.mp4" id="player"></video>
<div id="ppzone">
<div id="pp1"></div>
<div id="pp2"></div>
</div>
</div>
The second case, where you don't use absolute positioning at all, but rather display: table; css property, like bellow:
#pgzone{
border-style: solid;
width: 500px;
height: 600px;
border-width: 1px;
display: table;
box-sizing: border-box;
}
#pvidwrapper{
height: 0;
display: table-row;
}
#pvidwrapper video{
vertical-align: bottom;
}
#ppzone{
height: auto;
background-color: green;
display: table-row;
box-sizing: border-box;
}
<div id="pgzone">
<div id="pvidwrapper">
<video preload="auto" autoplay="true" width="100%" src="http://www.w3schools.com/html/mov_bbb.mp4" id="player"></video>
</div>
<div id="ppzone">
<div id="pp1"></div>
<div id="pp2"></div>
</div>
</div>

Related

How can I overlay image on top of video with resize?

Hello I have been trying to overlay an image on top of a video in a resizable container. I have tried many examples but each seems specific to the implementation.. My latest test is here https://jsfiddle.net/1Lfsy95w/ I can't get the video size to be correct and the image is out of the bounds.. Both should remain 16:9 aspect ratio, and be be resized of parent
#player-overlay {
display:block;
position: absolute;
width: 100%;
height: auto;
z-index: 4;
opacity: .5;
}
#OutputVideo {
display: block;
z-index: 1;
background-color:red;
width: 100%;
max-height:100%;
height:auto;
}
And the html
<div id="wrapper">
<img id="player-overlay" src="https://images.unsplash.com/photo-1580757468214-c73f7062a5cb"/>
<video id="OutputVideo">
<source src="http://techslides.com/demos/sample-videos/small.webm" type="video/webm">
</video>
</div>
Absolutely-positioned elements are set with with respect to the nearest non-static ancestor. You need to set position on your wrapper:
#wrapper {
position: relative;
}
To keep the image from pushing the wrapper below the video, hide overflow:
#wrapper {
position: relative;
overflow: hidden;
}
Fiddle demo
You can simplify things a bit by 1) putting the image as a background, and 2) moving the overlay after the video. This gives you more sizing flexibility and eliminates the need to fiddle with z-index.
#wrapper {
position: relative;
}
#player-overlay {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: .5;
background-image: url(https://...);
background-position: center;
background-size: cover;
}
<div id="wrapper">
<video controls id="OutputVideo">
<source src="http://....webm" type="video/webm">
</video>
<div id="player-overlay"></div>
</div>
Fiddle demo 2

Trouble placing video behind a div element

I'm trying to place a small video behind a banner-like div element. After some time researching I managed to at least show the contents of the div, but the video is nowhere to be seen. If I place them separately both show up, but if I try to stack them on top of each other it disappears.
HTML:
<div id="castle-siege">
<div id="cs-video">
<video id="videocs" width="100%" height="auto" autoplay="autoplay" loop="loop" preload="auto">
<source src=/assets/img/cs.mp4" type="video/mp4">
</video>
</div>
<div id="cs-table">
//content
</div>
</div>
CSS:
#castle-siege {
width: 1000px;
height: 150px;
text-align: center;
position: relative;
overflow: hidden;
}
#cs-video {
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 5;
}
#cs-table {
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
z-index: 10;
}
I think in this instance, that you need to set position attribute as well as z index in order to display the video properly. Also ensure your video is present and correct at the set url of course! Set the position of the video to absolute and set the table relative to it, either with a higher or lower z-index, as necessary (higher if you want it to be seen on top of the video)
For purposes of demo, I set the width to 80%, it's prob better to use percentages/ an adjustable unit, rather than setting the width in px.
Hope this helps
#castle-siege {
width: 80%;
height: 150px;
text-align: center;
position: relative;
overflow: hidden;
}
#cs-video {
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
z-index:0;
}
#cs-table {
width: 100%;
height: 100%;
margin-top: 30px;
margin-left: 50px;
color:red;
text-align:left;
position: relative;
z-index:1;
}
<div id="castle-siege">
<div id="cs-video">
<video id="videocs" width="100%" height="auto" autoplay="autoplay" loop="loop" preload="auto">
<source src="http://mirrors.standaloneinstaller.com/video-sample/jellyfish-25-mbps-hd-hevc.mp4">
</video>
</div>
<div id="cs-table">
Hi there, how's it going? There's supposed to be a table here.
</div>
</div>

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.

How to center an element based on the parent div?

I am trying to add a big play button on top of a video.
The video itself is responsive, and I want the play button to always be centered horizontally and vertically within the video.
It will be something like
---------------------------
| |
| |
| play button in center | <----video
| |
| |
---------------------------
I have something like:
<div style='text-align:center;'>
<div id='playIcon'><img src='play.png'/></div>
<video id='video' >
<source src=/video.mp4' type="video/mp4">
</video>
</div>
</div>
My css
#video{
width:100%;
max-height:1200px;
z-index: 1;
background-color: black;
}
How do I center the play button this case?
Here is a fiddle:
http://jsfiddle.net/Bc4NP/
You need to add position:relative to your main div:
<div style="text-align:center; position:relative">
<div id="playIcon"><img src="play.png" /></div>
<video id="video">
<source src="/video.mp4" type="video/mp4">
</video>
</div>
</div>
And then, add this styles to your play button:
#video{
width:100%;
max-height:1200px;
z-index: 1;
background-color: black;
}
#playIcon {
position: absolute;
top: 47%;
right: 0;
bottom: 0;
left: 0;
margin: auto;
}
Now you get an exact horizontal center align, and almost-exact vertical align (you can be more precise changing top:47%)
Since you have text-align center on the parent, that is good. So it will center it horizontally. It will be hard to get it exactly centered on every screen size vertically, but you can use media queries to help with that for differnet sizes.
An example would be the following. Adjust accordingly.
#playicon {
display: inline-block;
position: relative;
top: 40%;
}
Here is the code:
<div style='text-align:center;'>
<div id='playIcon'><img src='play.png'/></div>
<video id='video' >
<source src=/video.mp4' type="video/mp4">
</video>
</div>
<button id="bu">Play</button>
</div>
Here is the css:
#video{
width:200px;
max-height:150px;
z-index: -1;
background-color: black;
position:absolute;
top:0px;
left:0px;
}
#bu{
position:absolute;
top:75px;
left:100px;
}
Hope this works!
PS: Replace the button with an image of a play button.
Add
position: relative;
display: block;
top: 50%;
margin-top: -1000px;
height: 2000px;
text-align: center;
line-height: 2000px;
to the div containing the image (add this to your css):
#playIcon
{
position: relative;
display: block;
top: 50%;
margin-top: -1000px;
height: 2000px;
text-align: center;
line-height: 2000px;
}
It is a pure CSS2 solution that doesn't require different parameters according to the boundaries of your div.
Demo

use video as background for div

I would like to use a video as background in CSS3. I know that there is no background-video property, but is it possible to do this behavior. Using a fullsize video-tag doesn't give the wanted result, cause there is content that need to be displayed over the video.
It need to be non JS. If it is not possible then I need to do changes on my serverside an give as result also a screenshot of the video.
I need the video to replace the colored boxes:
The colored boxes are atm just, CSS boxes.
Pure CSS method
It is possible to center a video inside an element just like a cover sized background-image without JS using the object-fit attribute or CSS Transforms.
2021 answer: object-fit
As pointed in the comments, it is possible to achieve the same result without CSS transform, but using object-fit, which I think it's an even better option for the same result:
.video-container {
height: 300px;
width: 300px;
position: relative;
}
.video-container video {
width: 100%;
height: 100%;
position: absolute;
object-fit: cover;
z-index: 0;
}
/* Just styling the content of the div, the *magic* in the previous rules */
.video-container .caption {
z-index: 1;
position: relative;
text-align: center;
color: #dc0000;
padding: 10px;
}
<div class="video-container">
<video autoplay muted loop>
<source src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4" />
</video>
<div class="caption">
<h2>Your caption here</h2>
</div>
</div>
Previous answer: CSS Transform
You can set a video as a background to any HTML element easily thanks to transform CSS property.
Note that you can use the transform technique to center vertically and horizontally any HTML element.
.video-container {
height: 300px;
width: 300px;
overflow: hidden;
position: relative;
}
.video-container video {
min-width: 100%;
min-height: 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}
/* Just styling the content of the div, the *magic* in the previous rules */
.video-container .caption {
z-index: 1;
position: relative;
text-align: center;
color: #dc0000;
padding: 10px;
}
<div class="video-container">
<video autoplay muted loop>
<source src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4" />
</video>
<div class="caption">
<h2>Your caption here</h2>
</div>
</div>
Why not fix a <video> and use z-index:-1 to put it behind all other elements?
html, body { width:100%; height:100%; margin:0; padding:0; }
<div style="position: fixed; top: 0; width: 100%; height: 100%; z-index: -1;">
<video id="video" style="width:100%; height:100%">
....
</video>
</div>
<div class='content'>
....
Demo
If you want it within a container you have to add a container element and a little more CSS
/* HTML */
<div class='vidContain'>
<div class='vid'>
<video> ... </video>
</div>
<div class='content'> ... The rest of your content ... </div>
</div>
/* CSS */
.vidContain {
width:300px; height:200px;
position:relative;
display:inline-block;
margin:10px;
}
.vid {
position: absolute;
top: 0; left:0;
width: 100%; height: 100%;
z-index: -1;
}
.content {
position:absolute;
top:0; left:0;
background: black;
color:white;
}
Demo
I believe this is what you're looking for. It automatically scaled the video to fit the container.
DEMO: http://jsfiddle.net/t8qhgxuy/
Video need to have height and width always set to 100% of the parent.
HTML:
<div class="one"> CONTENT OVER VIDEO
<video class="video-background" no-controls autoplay src="https://dl.dropboxusercontent.com/u/8974822/cloud-troopers-video.mp4" poster="http://thumb.multicastmedia.com/thumbs/aid/w/h/t1351705158/1571585.jpg"></video>
</div>
<div class="two">
<video class="video-background" no-controls autoplay src="https://dl.dropboxusercontent.com/u/8974822/cloud-troopers-video.mp4" poster="http://thumb.multicastmedia.com/thumbs/aid/w/h/t1351705158/1571585.jpg"></video> CONTENT OVER VIDEO
</div>
CSS:
body {
overflow: scroll;
padding: 60px 20px;
}
.one {
width: 90%;
height: 30vw;
overflow: hidden;
border: 15px solid red;
margin-bottom: 40px;
position: relative;
}
.two{
width: 30%;
height: 300px;
overflow: hidden;
border: 15px solid blue;
position: relative;
}
.video-background { /* class name used in javascript too */
width: 100%; /* width needs to be set to 100% */
height: 100%; /* height needs to be set to 100% */
position: absolute;
left: 0;
top: 0;
z-index: -1;
}
JS:
function scaleToFill() {
$('video.video-background').each(function(index, videoTag) {
var $video = $(videoTag),
videoRatio = videoTag.videoWidth / videoTag.videoHeight,
tagRatio = $video.width() / $video.height(),
val;
if (videoRatio < tagRatio) {
val = tagRatio / videoRatio * 1.02; <!-- size increased by 2% because value is not fine enough and sometimes leaves a couple of white pixels at the edges -->
} else if (tagRatio < videoRatio) {
val = videoRatio / tagRatio * 1.02;
}
$video.css('transform','scale(' + val + ',' + val + ')');
});
}
$(function () {
scaleToFill();
$('.video-background').on('loadeddata', scaleToFill);
$(window).resize(function() {
scaleToFill();
});
});