Controlling position of text when positioned - html

I am trying to full width video the following code is a example. I don't want to restrict video by giving it a height as it is responsive, but the content or above positioned over it is pushing down when i view it on small screen e.g. Mobile
How can i make sure the text over the video shows at the same position even when screen is small and the text or panel below it also hide behind or hide/overlap the video.
I want to make the text on video and below be decent and not jumping or hiding. Am i using positions wrong?
.centered{
position: relative;
top:50%;
z-index: 1;
color:#fff;
text-shadow:1px 1px 10px #000;
}
video{
background-size:cover;
width: 100%;
position: absolute;
top:0;
}

Make sure the parent element has position: relative; and contains the video, and the parent adjusts responsively with the video. I do this by getting the aspect ratio of the video and creating padding (56.2%) that creates space for the video's aspect ratio (using the technique from the iframe section here), then put the text in that parent element and use a combination of position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); to center the text over the video.
* {margin:0;padding:0;}
#video {
height: 0;
padding-top: 56.2%;
position: relative;
overflow: hidden;
}
#video video {
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
-ms-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
background: url(polina.jpg) no-repeat;
background-size: cover;
}
#video h1 {
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%,-50%);
color: #fff;
text-shadow: 1px 1px 10px #000;
font-size: 36px;
font-family: sans-serif;
text-align: center;
}
<div id="video">
<video poster="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/polina.jpg" id="bgvid" playsinline="" autoplay="" muted="" loop="">
<source src="http://thenewcode.com/assets/videos/polina.webm" type="video/webm">
<source src="http://thenewcode.com/assets/videos/polina.mp4" type="video/mp4">
</video>
<h1>We Evolve with our students
</div>

I think this link will help you about centring anything ;)
About positioning text, you can use vh value. Ie.
.text {
position: absolute;
top: 30vh
}
Also, this guy from the top have a good example about absolute positioning ;)
Link about vh

Here is the css for the div with centerred class. Hope this will help you.
change the position to absolute and use the calc function to position the text to center from top
.centered
{
position: absolute;
top: calc(100% - 50%);
text-align : center;
left : 0;
right : 0;
z-index: 1;
color:#fff;
text-shadow:1px 1px 10px #000;
}

Related

Just need a little validation on how to fit a background video fit to screen with an overlay text

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

How to set a spinner into the middle of the screen while loading with CSS?

My spinner is in the middle of the screen after a second of loading the page. But at the first frame of the page, it is not centered, instead it is positioned on the top-left of the page. How to make sure my spinner is centered from the start? I do not have problems centering the loader. I just need to make sure my spinner starts in the middle of the page. I already looked for similar problems but they are not the same. Here is my css.
.loader {
/*left: 50%;
position: fixed;
top: 50%;
transform: translate3d(-50%, -50%, 0);
z-index: 999;*/
position: fixed;
z-index: 999;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
html:
<div class="loader">
<img src="../../../../assets/content/Amsa-loading.gif">
</div>
Try
<div class="app_loader"></div>
.app_loader{
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
What I do to make this work is use a background instead of img tag:
.loader{
height:100%;
width:100%;
background:url(/design/images/loader.gif) no-repeat center center;
position:absolute;
z-index:10;
}
then for the HTML:
<div class="loader"></div>
then in my site's CSS, hide the div when the CSS is loaded.
.loader{display:none;}

Image not repeating properly

I'm trying to make a small image repeat as an overlay across the entire background video, but it just isn't working. I got it to this point and I've tried every multitude things I can think of. Any suggestions?
Code:
.overlay {
position: relative;
z-index: 2;
overflow: hidden;
opacity: 0.7;
background: #000 url(../media/overlay.png) repeat;
}
.content {
position: relative;
top: 30%;
z-index: 3;
margin: 0 auto;
max-width: 720px;
text-align: center;
}
.video {
position: fixed;
top: 50%;
left: 50%;
z-index: 1;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<div>
<div class="overlay">
<img src="/media/overlay.png" />
</div>
<div class="content">
<h1 class="content__heading"><img src="/media/logo.png" /></h1>
<p class="content__teaser"> tba. </p>
tba.
</div>
<video id="my-video" class="video" muted loop>
<source src="media/bg.mp4" type="video/mp4">
</video></div>
Your overlay isn't big enough to show the repeating background.
try making the overlay full-page:
.overlay {
width: 100%;
height: 100%;
}
You don't need to include the <img> in the HTML, since you already display the image using a CSS background.
See a working example here (Note: I had to make .overlay position: absolute so that the overlay covers the whole height of the page)

Change the height of a video and keep the same width

I have a video And I want to change the height and keep the same width For example width on full screen I Think is 100% and Height Just 200px same to this website www.paypal.com
The Problem is when I change the height width also change automatically, And video go to the center(stretched horizontally)
<video autoplay class="embed-responsive-item">
<source src=test.mp4 type=video/mp4>
</video>
video{ width: 100%; height: 200px; }
Thanks Advance For any help
That PayPal website uses the CSS property object-fit: cover to fit the video the same width.
The object-fit CSS property specifies how the contents of a replaced element should be fitted to the box established by its used height and width.
https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit
.hero-home video {
display: block;
height: 100%;
width: 100%;
top: 0px;
position: absolute;
left: 0px;
z-index: -1;
object-fit: cover; /* this makes it fit within the video container */
opacity: 0.9;
transition: opacity 0.3s ease 0s;
}
Possible values for object-fit
/* Keyword values */
object-fit: fill;
object-fit: contain;
object-fit: cover;
object-fit: none;
object-fit: scale-down;
/* Global values */
object-fit: inherit;
object-fit: initial;
object-fit: unset;
They also are using a mix of max-width, min-width, and min-height on the some of the parent elements of the <video> element.
Just inspect the CSS to see what their doing. You will see that part of the video is being hidden, not displaying all the height of the video on the .video-container using overflow:hidden.
Hi you can give width and height to the container your video is in and then give the video element min-width/height like this the video will stay in the center and only the width will change and not the height.
.container {
width: 100%;
height: 100%;
}
video {
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 200px;
width: auto;
height: auto;
}

HTML video to cover 100% div

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