我有以下简单的代码:
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html ns=\"http://www.w3.org/1999/xhtml\" :lang=\"en\">
<head>
< >Live Feed</ >
< http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div style=\"background-color: #eeeeee; width: 250px; height: 100%; border-right: solid 1px #e1e1e1;\">
I should be tall
</div>
</body>
</html>
可div并没有按照所想的那样展开,但将div设置固定高度时能够正常展开,这是什么原因?
因为在给元素设置百分比高度时要制定父布局高度,在这里我们需要设置body和HTML的高度。 真确代码如下:
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html ns=\"http://www.w3.org/1999/xhtml\" :lang=\"en\">
<head>
< >Live Feed</ >
< http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />
<style>
body {
margin: 0px;
padding: 0px;
height:100%;
}
html{
height:100%;
}
</style>
</head>
<body>
<div style=\"background-color: #eeeeee; width: 250px; height: 100%; border-right: solid 1px #e1e1e1;\">
I should be tall
</div>
</body>
</html> 继续阅读与本文标签相同的文章
-
性能优化之卡顿延迟
2026-05-14栏目: 教程
-
第16问:Filecoin从DSN角度解读
2026-05-14栏目: 教程
-
C/C+从零基础到精通,究竟是如何快速完成的?其实只需要这6步!
2026-05-14栏目: 教程
-
谷歌再爆重大安全漏洞!华为却成最大赢家?网友:这谁还敢用!
2026-05-14栏目: 教程
-
Excel崩溃文件如何找回
2026-05-14栏目: 教程
