限制高度的最佳方法:100% ... - 50px?

Mar*_*rco 3 html css

限制此类事件的最佳方法应该是什么?

高度:100%,但我需要 100% - 50px !!! ,我该如何计算或解决该问题?

提前致谢!

马可,

mar*_*123 5

如果您需要底部 50 像素,只需将容器向上拖动 50 像素并使用负边距,并给它 100% 的高度。像这样的东西应该有效:

<!DOCTYPE html>
<html>
<head>
    <title>100% minus 50px</title>
    <style type="text/css">
        html, body {
            height: 100%;
        }
        body {
            background: #000;
            margin: 0;
        }
        #almost100 {
            padding-top: 50px;
            height: 100%;
        }
        #container {
            background: #f08;
            min-height: 100%;
            margin-top: -50px;
        }
        p {
            margin: 0;
        }
        #footer {
            background: #f00;
            height: 50px;
        }
    </style>
</head>
<body>
    <div id="container">
        <div id="almost100">
            <p>:)</p>
        </div>
    </div>
    <div id="footer">
    </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)