简体   繁体   中英

Center full screen div with margin

I don't know how to center a full screen div. I want to center a div with width: 90% and height: 90% , but when I use this code:

 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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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