簡體   English   中英

將全屏div居中對齊

[英]Center full screen div with margin

我不知道如何將全屏div居中。 我想將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> 

我得到了一些我不想要的滾動條。

用這個:

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