How to center HTML5 Videos?

后端 未结 15 1785
终归单人心
终归单人心 2021-01-31 02:25

I\'m just messing around with some HTML5, and I was trying to center a video on the page. For some reason I can\'t get it to center. I\'ve tried to add a class to the video tag

15条回答
  •  失恋的感觉
    2021-01-31 02:53

    Use margins is an inline element so you'll have to add display block;to your css class.

    You can use specific with, but I wouldn’t use px values. Use % to make it responsive, like:

    width: 50%;
    

    That’ll make the video half of the viewport width.

    See the original documentation here O World Wide Web Consortium W3C

    mystyle.css

    video {
          width: 50% !important;
          height: auto !important;
          margin: 0 auto;
          display: block;
        }
    
        h1 {
          text-align: center;
          color: #C42021;
          font-size: 20px;
        }
    
            
               
                  
                  Test
                   
               
               
                  

    How do you center a video

    See the code ready here for more understanding.

    You can view the code online Fiddle

提交回复
热议问题