html - 在 HTML body 标签中构建 3 个不同的部分
问题描述
我一直在尝试设置我的网站主体,使其由三个部分组成——主要部分(用于幻灯片/图像)、中间部分(白色背景)和页脚(灰色背景)。我该怎么做呢?到目前为止,我已经尝试扩展一个制作简单页脚的教程,以允许我添加第三部分。我的 HTML 和 CSS 片段如下:
索引.html
<body bgcolor="#212121">
<div id="wrapper">
<div id="content">
<p>text</p>
</div>
</div>
<div id="midsection"><div id="mid-content">Mid</div></footer>
<footer id="footer"><div class="footer">Footer</div></footer>
</body>
样式.css
html, body {
margin: 0px;
padding: 0px;
min-height: 100%;
height: 100%;
}
#wrapper {
background-color: #212121;
min-height: 100%;
height: auto !important;
margin-bottom: -300px; /* the bottom margin is the negative value of the footer's total height */
}
#wrapper:after {
content: "";
display: block;
height: 300px; /* the footer's total height */
}
#content {
height: 100%;
}
#midsection {
height: 300px; /* the footer's total height */
margin-bottom: -100px;
}
#midsection:after {
content: "";
display: block;
height: 100px;
}
#mid-content {
background-color: #f9f9f9;
height: 284px; /* height + top/bottom paddding + top/bottom border must add up to footer height */
padding: 8px;
}
/* main image section (wrapper) + mid section */
#footer {
height: 100px;
}
#footer-content {
background-color: #808080;
}
理想情况下,我希望中间部分为 300 像素,页脚为 100 像素。
解决方案
这个怎么样:
html中有一些错误。记得正确关闭 html 标签。希望这可以帮助。
html:
<body>
<div id="wrapper">
<div id="content">
<p>text</p>
</div>
</div>
<div id="midsection">
<div id="mid-content">Mid</div>
</div>
<footer id="footer">
<div class="footer">Footer</div>
</footer>
</body>
CSS:
html, body {
margin: 0px;
padding: 0px;
min-height: 100%;
height: 100%;
background-color: #212121;
}
#wrapper {
min-height: 100%;
height: auto !important;
margin-bottom: -300px; /* the bottom margin is the negative value of the footer's total height */
}
#wrapper:after {
content: "";
display: block;
height: 300px; /* the footer's total height */
}
#content {
height: 100%;
}
#midsection {
background-color: white;
height: 300px; /* the footer's total height */
margin-bottom: -100px;
}
#midsection:after {
content: "";
display: block;
height: 100px;
}
#footer {
background-color: #212121;
height: 200px;
}
推荐阅读
- fish - 如何混合使用函数和纯文本来设置鱼的问候?
- c# - 如何在 ASP.NET Core 2.2 中创建角色并将其分配给用户
- android - 在没有互联网的情况下从 WLAN 请求下载时,Android 9 无法开始下载
- python - 尝试从导入的模块中引用会话时,SQLAlchemy '没有这样的表'
- swift - Keyboard does not resign from view
- javascript - Importrange 使用脚本一次更改多个电子表格中的单元格
- encoding - 如何将 NSIS 中的字符串编码为 UTF-16LE 格式?
- python - 图像检测的嵌套循环需要永远运行 1 亿次
- javascript - 正则表达式仅匹配第一次或仅第二次出现
- php - 删除模型时分离数据透视表中模型的每条记录