How to align iframe always in the center

前端 未结 6 1518
臣服心动
臣服心动 2021-01-02 12:58

I have an iframe surrounded by div element and I am simply trying to position it always in the center. here is my jsfiddle effort : jsfiddle

and tr

6条回答
  •  攒了一身酷
    2021-01-02 13:35

    If all you want to do is display an iframe on a page, the simplest solution I was able to come up with doesn't require divs or flex stuff is:

    html {
        width: 100%;
        height: 100%;
        display: table;
    }
    
    body {
        text-align: center;
        vertical-align: middle;
        display: table-cell;
    }
    

    And then the HTML is just:

    
      
         
      
    
    

    If this is all you need you don't need wrapper divs to do it. This works for text content and stuff, too.

    Fiddle.

    Also this looks even simpler.

提交回复
热议问题