I'm trying to place text over a video on my site, but to do this I had to use a position: fixed; element so the text would appear in front of the video. I thought that doing this would just fix it to the one spot and that position: absolute; was the one that would have kept the text in place when scrolling. I don't want the text to be visible once you've scrolled past the video. I'm also trying to keep the video in the center of the page. Right now I'm using a left and right margin of 120px but it's not perfect.
<div class="container">
<video id="video" width="770" height="882" playsinline controls autoplay muted loop>
<source src="video/Cage_Broken_Boy.mp4" type="video/mp4"/>
</video>
</div>
<div class="overlay">
<h1>CAGE THE ELEPHANT</h1>
<h2 class="info">PERFORMING
JUNE 27 7:00PM
SARATOGA PERFORMING
ARTS CENTER
</h2>
</div>
/css/
video{
justify-content: center;
display: block;
width: 90%;
height: auto;
margin-left: 120px;
margin-right: 120px;
-o-object-fit: cover;
object-fit: cover;
-o-object-position: center;
object-position: center;
}
.container {
position:relative;
}
.container video {
position:relative;
z-index:0;
}
.overlay {
position: fixed;
justify-content: center;
text-align: center;
top:50%;
left:50%;
z-index: 1;
transform: translate(-50%, -50%);
}
.info{
font-family: urw-form-expanded, sans-serif;
font-weight: 400;
font-style: normal;
-webkit-text-stroke-width: 2px;
-webkit-text-stroke-color: white;
}
So you do want to use position: absolute; and use margin: 0 auto; or just margin: auto; to center the video.
You have to place the overlay inside the video container to make it work:
video {
margin: 0 auto;
}
.overlay {
position: absolute;
}
<div class="container">
<video id="video" width="770" height="882" playsinline controls autoplay muted loop>
<source src="video/Cage_Broken_Boy.mp4" type="video/mp4"/>
</video>
<div class="overlay">
<h1>CAGE THE ELEPHANT</h1>
<h2 class="info">PERFORMING
JUNE 27 7:00PM
SARATOGA PERFORMING
ARTS CENTER
</h2>
</div>
</div>
See this JSFiddle: https://jsfiddle.net/qcgv6znd/1/
Related
I'm working on a website where I have a background video playing, and I want to display a company logo over that background video while it plays. I want that logo to be centered. I'm using HTML and CSS. Right now, my HTML code for that section is:
#reel {
position: absolute;
visibility: hidden;
right: 0;
top: 8px;
min-width: 100%;
min-height: 100%;
}
#overlay {
top: 50%;
}
<!-- BACKGROUND REEL-->
<div>
<video playsinline autoplay muted loop id="reel">
<source src="Media/Reel.mp4" type="video/mp4">
</video>
<img class="overlay" width="40%" src="Media/Transparent.png">
</div>
For whatever reason, I can't quite get it to center. I want the page to be able to shrink and have the logo stay in the center but right now it's not. Does anyone know why?
#wrapper {
position: relative;
display: inline-block;
}
#reel {
width: 100vw;
}
.overlay {
position: absolute;
width: 40%;
left: 30%;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
<div id="wrapper">
<video playsinline autoplay muted loop id="reel">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
<img class="overlay" src="https://www.w3schools.com/images/driveicon_32.png">
</div>
I think this code might help you.
(Please change the "src" attribute in real usage.)
Best regards
I modify some code & content in HTML structure, I use background image for overlay.
.video-wrapper {
position: relative;
height: 100%;
width: auto;
display: table;
}
.video-wrapper video#reel {
position: relative;
visibility: visible;
width: auto;
display: table;
object-fit: cover;
}
.video-wrapper:after {
content: '';
left: 0;
height: 100%;
width: 100%;
top: 0;
position: absolute;
z-index: 999;
opacity: 0.5;
background-image: url('https://cdn.pixabay.com/photo/2016/11/22/21/57/apparel-1850804_960_720.jpg');
}
<!-- BACKGROUND REEL-->
<div class="video-wrapper">
<video id="reel" poster="" playsinline="" autoplay="" muted="" loop="">
<source src="https://assets.mixkit.co/videos/preview/mixkit-woman-modeling-a-short-black-dress-805-large.mp4" type="video/mp4">
<img class="overlay" src="https://cdn.pixabay.com/photo/2016/11/22/21/57/apparel-1850804_960_720.jpg">
</div>
<div id='box'>
<video playsinline autoplay muted loop id="reel">
<source src="Media/Reel.mp4" type="video/mp4">
</video>
<img class="overlay" src="Media/Transparent.png">
</div>
<style>
#box {position:fixed;width:100%;height:100%;}
#reel {position:absolute;width:100%;height:100%;}
.overlay {width:60px;height:40px;top:calc(50% - 20px);left:calc(50% - 30px);position:absolute;}
</style>
I am not able to fit the background video fit the screen for all devices and browsers. Somehow I am success full in doing it on chrome browser. Earlier it was clipping on both the sides of chrome browser. Now I realize that it is fine on chrome but the problem persists on IE edge
I Have already written the code just need a validation from experts or any improvement on it
here is the code pen https://codepen.io/jslearner1/pen/ydrzZz?editors=1100
*{
margin:0;
padding:0;
}
body{
font-size: 62.5%;
box-sizing: border-box;
font-family: 'Lato',sans-serif;
letter-spacing: 0.5px;
line-height: 1.7;
background-color: #fcfcfc;
}
.header{
width: 100%;
height: 100vh;
font-size: 2rem;
color: #fcfcfc;
position: relative;
z-index: 99;
overflow: hidden;
.overlay{
position: absolute;
top:0;
left: 0;
width: 100%;
height: 100vh;
background-color: rgba(#000000,0.8);
z-index: 1;
&__text{
position: absolute;
top:50%;
left: 50%;
transform: translate(-50%,-50%);
}
}
}
.bg_video{
position: absolute;
top:0;
left:0;
width: 100%;
height: 100vh;
object-fit: cover;
}
<body>
<header class="header">
<div class="overlay">
<div class="overlay__text">
<p>Welcome !!!</p>
</div>
</div>
<!-- Video Taken from George Park Code pen -->
<video autoplay muted loop class="bg_video">
<source src="http://www.georgewpark.com/video/blurred-street.mp4" type="video/mp4">
<source src="http://www.georgewpark.com/video/blurred-street.mp4" type="video/webm">
your browser is not supported
</video>
</header>
</body>
Similar to this issue: IE and Edge fix for object-fit: cover;
Basically object-fit doesn't really work in Edge (despite being supported).
Replace your .bg_video css with this:
.bg_video{
position: absolute;
top:50%;
left:50%;
width: 100%;
height:auto;
transform: translate(-50%, -50%);
}
You can use the object-fit proprety :
.bg_video {
object-fit : cover;
}
I have the following markup:
.jumbotron {
position: relative;
z-index: -101;
overflow: hidden;
height: 500px;
background: red;
}
.jumbotron video {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
z-index: -100;
}
.video-content {
text-align: center;
color: #fff;
}
<div class='jumbotron'>
<video autoplay loop class="fillWidth">
<source src="https://ia800201.us.archive.org/12/items/BigBuckBunny_328/BigBuckBunny_512kb.mp4" type="video/mp4" />
<source src="video.ogv" type="video/ogv" />
<source src="video.webm" type="video/webm" />Your browser does not support the video tag. I suggest you upgrade your browser.
</video>
<div class='video-content'>
<h1>Welcome to the Site</h1>
<p>This is just a test but it shows a background video</p>
</div>
</div>
<div class='container-fluid'>
<div class='row'>
<div class='col-md-12'>
<h2>Section Heading</h2>
</div>
</div>
</div>
My question is around the responsiveness of the video background. When I make the viewport smaller the video eventually begins to shrink and the parent div remains longer then it - resulting in an unwanted red background.
How can I ensure the parent div scales with the size of the video? So that when I bring it right down to > 480px the h2 tag will be right below the video.
You can see a a fiddle here
This will work for you :)
.jumbotron {
position: relative;
height: 500px;
overflow: hidden;
}
.jumbotron video {
position: absolute;
bottom: 50%;
right: 50%;
-webkit-transform: translateX(50%) translateY(50%);
transform: translateX(50%) translateY(50%);
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -1000;
overflow: hidden;
}
you can change the fixed height to padding-bottom in .jumbotron
.jumbotron {
position: relative;
padding-bottom: 56.25%;
/* 16:9 */
height: 0;
background: red;
}
.jumbotron video {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%
}
.video-content {
text-align: center;
color: #fff;
}
<div class='jumbotron'>
<video autoplay loop class="fillWidth">
<source src="https://ia800201.us.archive.org/12/items/BigBuckBunny_328/BigBuckBunny_512kb.mp4" type="video/mp4" />
<source src="video.ogv" type="video/ogv" />
<source src="video.webm" type="video/webm" />Your browser does not support the video tag. I suggest you upgrade your browser.
</video>
<div class='video-content'>
<h1>Welcome to the Site</h1>
<p>This is just a test but it shows a background video</p>
</div>
</div>
<div class='container-fluid'>
<div class='row'>
<div class='col-md-12'>
<h2>Section Heading</h2>
</div>
</div>
</div>
Not sure if I understood. I made the video fill the screen, by changing its height and width to the viewport size. But needs to keep the aspect ratio.
.jumbotron video {
...
height: 100vh;
width: 100vw;
...
}
Researched elsewhere, can't find a solution to horizontally center a video in a Bootstrap div / header section while keeping the video vertically aligned with the top. Div / header section is 100% width with two fixed heights at certain viewport breakpoints.
I've tried removing/renaming the <header> tag in case Bootstrap's styles interfere. Tried <center> tags, specifying the video tag as display:inline and many many other attempts.
The video in this example centers at certain breakpoints but otherwise is left-aligned. I'd like it to be centered throughout all viewport widths, and top aligned as well.
Thanks very much!
HTML:
<header>
<video loop muted autoplay poster="images/3671960.jpg" class="fullscreen-video">
<source src="video/3671960.mp4" type="video/mp4">
</video>
<div class="header-content">
<div class="header-content-inner">
<h1>A bunch of header text.</h1>
</div>
</div>
<div class="launcher">
<div class="launcher-inner">
Button text
</div>
</div>
CSS :
header {
position: relative;
text-align: center;
top: 0;
left: 0;
width:100%;
height: 475px;
color: #fff;
overflow: hidden;
margin: 0 auto;
}
header .fullscreen-video {
position: absolute;
top: 0;
left: 0;
min-width:100%;
min-height:100%;
z-index: -100;
}
#media (min-width: 768px) {
header {
height: 665px;
}
}
HTML
<header>
<video loop muted autoplay poster="images/3671960.jpg" class="fullscreen-video">
<source src="video/3671960.mp4" type="video/mp4">
</video>
<div class="header-content">
<div class="header-content-inner">
<h1>A bunch of header text.</h1>
</div>
</div>
<div class="launcher">
<div class="launcher-inner">
Button text
</div>
</div>
</header>
CSS
header {
position: relative;
text-align: center;
top: 0;
left: 0;
width:100%;
height: 475px;
color: #fff;
overflow: hidden;
margin: 0 auto;
}
header .fullscreen-video {
position: absolute;
left: 50%;
top: 0;
-ms-transform: translateX(-50%);
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
min-width:100%;
min-height:100%;
z-index: -100;
}
#media (min-width: 768px) {
header {
height: 665px;
}
}
Demo Link : https://jsfiddle.net/hellosrini/vwc5hek0/
I have an HTML video that I want to use as replacement for a background image that would be fullscreen, However currently it overflows and covers the entire page instead of just the constraints of the header.
html:
<header id="masthead" class="site-header" role="banner">
<video autoplay loop poster="<?php bloginfo('stylesheet_directory'); ?>/img/main.jpg" id="bgvid">
<source src="<?php bloginfo('stylesheet_directory'); ?>/vid/dumbells.webm" type="video/webm">
<source src="<?php bloginfo('stylesheet_directory'); ?>/vid/dumbells.mp4" type="video/mp4">
</video>
</header>
css:
video#bgvid {
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%);
background: url(img/main.jpg) no-repeat;
background-size: cover;
}
.site-header {
left: 0px;
top:0px;
z-index: 1;
float: none;
width: 100%;
height: 100%;
overflow:hidden;
text-align:center;
padding: 130px 0 141px;
}
Does anyone know what i have to do, to allow it just to fill the size of my header container? There's a few questions on a similar subject but none seem to answer my specific query.
Apply
position:relative
to your .site-header class