css身高80%无法正常工作

ast*_*ght 4 css

我想让我的表占据屏幕的80%,但现在它只是表中内容的大小.

#ecom-mainarea .center
{
margin-left: 10%;
position: relative;
width: 80%;
height: 80%;   /* when this is 500px it works fine, but % doesn't work */ 
border: 1px solid;
border-bottom-color: teal;
border-top-color: gray;
border-left-color: gray;
border-right-color: teal;
background-color: white;
voice-family: "\"}\"";
voice-family: inherit;
vertical-align: text-top;
}
Run Code Online (Sandbox Code Playgroud)

knu*_*nut 8

你需要确保htmlbody元素有100%高度.他们需要从上到下伸展.如果不是htmlbody元素只会高达你的表.

这里有一个工作样本:

<!doctype html>
<html>
<head>
    <title>Table height</title>
    <style>
        html, body
        {
            padding: 0;
            margin: 0;
            height: 100%;
        }
    </style>
</head>
<body>
    <table style="background: cyan; height: 80%;">
        <tr>
            <td>
                Table has 80% of the height of the body
            </td>
        </tr>
    </table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)