我已经创建了带有标题,菜单和内容部分的HTML模板:
<html>
<head>
<style>
#header {
background-color: red;
width: 100%;
height: 85px;
}
#below-header {
background-color: yellow;
position: relative;
height: 200px;
}
#menu {
background-color: blue;
position: absolute;
width: 200px;
height: 150px;
}
#content {
padding-left: 200px; /* menu */
background-color: green;
height: 150px;
}
</style>
</head>
<body>
<div id="header">header</div>
<div id="below-header">
<div id="menu">menu</div>
<div id="content">content</div>
below-header
</div>
</body>
</html>
但是,当插入带有空白的块元素(例如h1标签)时,会有一个难看的间隙:
<html>
<head>
<style>
#header {
background-color: red;
width: 100%;
height: 85px;
}
#below-header {
background-color: yellow;
position: relative;
height: 200px;
}
#menu {
background-color: blue;
position: absolute;
width: 200px;
height: 150px;
}
#content {
padding-left: 200px; /* menu */
background-color: green;
height: 150px;
}
</style>
</head>
<body>
<div id="header">header</div>
<div id="below-header">
<div id="menu">menu</div>
<div id="content">
<h1>headline in content</h1>
</div>
below-header
</div>
</body>
</html>
删除边距或将h1元素转换为inline-block
元素时,间隙消失了。