Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertically centering video inside a video tag

how do you center vertically a video inside a video tag? currently the video is flush top and the bottom is getting cut off. what i would like to do is for the middle of the video to be in the middle of the video container. the video's height will vary because it's responsive so as the browser becomes smaller so does the video. here's my code:

html

<div id="video-wrap">
    <video preload="auto" autoplay loop muted>
        <source type="video/mp4" src="video.mp4">
    </video>
</div>

css:

#video-wrap {
    width: 100%;
    height: 400px;
    overflow: hidden;
}
like image 400
midknyte Avatar asked Feb 20 '15 17:02

midknyte


People also ask

How do I center align a video in HTML?

You can either set the video's width in HTML or use the CSS' width property. In CSS, select the center class and set the text-align property to center . Thus, the video will be centered.

How do you center a vertical label?

Select the text that you want to center. in the Page Setup group, and then click the Layout tab. In the Vertical alignment box, click Center.


1 Answers

These three lines should do:

video{
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

Let me know if it works :)

like image 73
m0bi5 Avatar answered Oct 16 '22 17:10

m0bi5