Html 如何使 div 占页面大小的 80%?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4317924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:30:54  来源:igfitidea点击:

How can I make a div 80% the size of the page?

csshtml

提问by Geo

I'd like to make a page container div have a top margin of 10% and bottom margin of 10%. How can I make the div take the remaining 80% of the page, all the time ( no matter if it has content or not )?

我想让页面容器 div 的上边距为 10%,下边距为 10%。我怎样才能让 div 一直占据页面剩余的 80%(无论它是否有内容)?

回答by tdammers

This should work:

这应该有效:

<!DOCTYPE html>
<html>
    <head>
        <style type="text/css">
            div { 
                position: absolute;
                height: 80%; 
                width: 80%; 
                top: 10%; 
                left: 10%; 
                background-color: #FFCC00; 
            }
        </style>
    </head>
    <body>
        <div>
            This should prove my point.
        </div>
    </body>
</html>

回答by OV Web Solutions

You can try:

你可以试试:

CSS
---
.container {
   margin-top:10%;
   margin-bottom:10%;
   height:80%;
}

<div class="container"></div>