【发布时间】:2016-12-15 09:39:47
【问题描述】:
我正在尝试完成一些非常简单的事情。我糟糕的生锈 CSS 技能一点帮助都没有。
我做不到。如果我使用height: 100%,它可以在文本不多的情况下工作,但是当我添加大量 Lorem Ipsum 时,内容 div 会被拉伸,并且左侧菜单 div 不会随之缩放。
我不想使用 JavaScript,如果可能的话,就清理 CSS。
HTML:
<html>
<head>
<title>test</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id="header">Header</div>
<div id="menu">Menu</div>
<div id="content">Content (paste a lot of lorem ipsum here and menu doesn't stretch)</div>
</body>
</html>
CSS
body
{
margin: 0;
height: 100%;
background-color: gray;
}
#header
{
height: 50px;
background-color: white;
border: 1px solid black;
}
#menu
{
width: 225px;
float: left;
height: calc(100% - 50px);
background-color: white;
border: 1px solid black;
}
#content
{
overflow: auto;
background-color: white;
border: 1px solid black;
}
【问题讨论】:
-
弹性盒子正是您想要的。 - css-tricks.com/snippets/css/a-guide-to-flexbox
-
其实并没有你想的那么简单,这是很多人提出的常见设计要求,不是直截了当或“开箱即用”
-
您想要的外观看似简单,但实际上并非如此。你问了很多浏览器。而且,高度 100% 不会像您认为的那样做:stackoverflow.com/questions/7880365/…。最后,您不想要 100% - 您想要 100% 减去标题的高度。