简体   繁体   English

将全屏div居中对齐

[英]Center full screen div with margin

I don't know how to center a full screen div. 我不知道如何将全屏div居中。 I want to center a div with width: 90% and height: 90% , but when I use this code: 我想将div的width: 90%height: 90%居中,但是当我使用此代码时:

 html, body { width: 100%; height: 100%; } .outer { height: 100%; position: relative; text-align: center; width: 100%; } .inner { height: 90%; width: 90%; position: relative; top: 5%; background: red; margin: 0 auto; } 
 <div class="outer"> <div class="inner"> </div> </div> 

I get a little bit of scroll that I don't want. 我得到了一些我不想要的滚动条。

Use this: 用这个:

html,body {
    margin: 0;
   //other codes...
}

 html, body { width: 100%; height: 100%; margin: 0; } .outer { height: 100%; position: relative; text-align: center; width: 100%; } .inner { height: 90%; width: 90%; position: relative; top: 5%; background: red; margin: 0 auto; } 
 <div class="outer"> <div class="inner"> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM