html - 将“页脚”粘贴到 div 的底部而不是页面
问题描述
我一直试图让一个 div 在它的边界 div 而不是浏览器窗口中表现得像一个页脚。我运气不太好。需要将此代码插入到主站点上的边界 div 中,并将该 div 视为浏览器窗口。如果页面太小,内容是可滚动的,但“页脚”标签始终保持可见并位于边界 div 的底部。
<style type="text/css" scoped>
.header {
width: auto;
}
/*bottom sticky div */
.sticky {
width: auto;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 10%;
background: red;
}
/* Rest is just the fluid columns .css */
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float: left;
margin: 1% 0 1% 1.6%;
}
.col:first-child {
margin-left: 0;
}
/* GROUPING */
.group:before,
.group:after {
content: "";
display: table;
}
.group:after {
clear: both;
}
.group {
zoom: 1;
/* For IE 6/7 */
}
/* GRID OF FOUR */
.span_4_of_4 {
width: 100%;
}
.span_3_of_4 {
width: 74.6%;
}
.span_2_of_4 {
width: 49.2%;
}
.span_1_of_4 {
width: 23.8%;
}
/* GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
.col {
margin: 1% 0 1% 0%;
}
.span_1_of_4,
.span_2_of_4,
.span_3_of_4,
.span_4_of_4 {
width: 100%;
}
}
</style>
<div header>Hello world
</div>
<div class="section group">
<div class="col span_1_of_4">
<p>1 of 4 </p>
<img src="http://www.nathanielmcmahon.com/assets/images/about_page/OMA%20cctv%20building_.jpg" alt="CCTV building in Beijing By Rem Koolhaas's OMA" style="margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;width:100%;" /> Since 2011 Nathaniel
has been scaling China's highs and lows documenting it's varied architectural manifestations for a range of western and Local clients. Often a lone cameraman amongst a sea of Chinese hard hats, part of the job has been to negotiate sites with little
more than a grid reference and reference pictures in inhospitable new cities on the fringes of boom or bust development. Scrambling his way up a half finished sky scrapper fire escapes with little more than a telephone number and the name of a contractor
called Zhou. In the summer of 2017 he relocated to London. He looks forward to shooting a very different type of architecture back home.
</div>
<div class="col span_1_of_4">
2 of 4
</div>
<div class="col span_1_of_4">
3 of 4
</div>
<div class="col span_1_of_4">
4 of 4
</div>
</div>
<div class="sticky group">
<div class="col span_1_of_4">
a of 4
</div>
<div class="col span_1_of_4">
b of 4
</div>
<div class="col span_1_of_4">
c of 4
</div>
<div class="col span_1_of_4">
d of 4
</div>
</div>
</div>
解决方案
为了实现这一点,您可以拥有一个容器 div,其位置为:relative,然后其中的“页脚”位置为“绝对”。
对于滚动,在容器中有另一个 div 具有设定的高度,溢出设置为“自动”,其中的“页面”内容。
请参阅下面的片段:
<style type="text/css" scoped>
.header {
width: auto;
}
/*bottom sticky div */
.sticky {
width: auto;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 30px;
background: red;
}
/* Rest is just the fluid columns .css */
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float: left;
margin: 1% 0 1% 1.6%;
}
.col:first-child {
margin-left: 0;
}
/* GROUPING */
.group:before,
.group:after {
content: "";
display: table;
}
.group:after {
clear: both;
}
.group {
zoom: 1;
/* For IE 6/7 */
}
/* GRID OF FOUR */
.span_4_of_4 {
width: 100%;
}
.span_3_of_4 {
width: 74.6%;
}
.span_2_of_4 {
width: 49.2%;
}
.span_1_of_4 {
width: 23.8%;
}
/* GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
.col {
margin: 1% 0 1% 0%;
}
.span_1_of_4,
.span_2_of_4,
.span_3_of_4,
.span_4_of_4 {
width: 100%;
}
}
</style>
<div header>Hello world
</div>
<div style="position:relative"> <!-- THE CONTAINER DIV -->
<div style="height:150px; overflow:auto"> <!-- CONTENT DIV THAT SCROLLS -->
<div class="section group">
<div class="col span_1_of_4">
<p>1 of 4 </p>
<img src="http://www.nathanielmcmahon.com/assets/images/about_page/OMA%20cctv%20building_.jpg" alt="CCTV building in Beijing By Rem Koolhaas's OMA" style="margin-top:0;margin-bottom:0;margin-right:0;margin-left:0;width:100%;" /> Since 2011 Nathaniel
has been scaling China's highs and lows documenting it's varied architectural manifestations for a range of western and Local clients. Often a lone cameraman amongst a sea of Chinese hard hats, part of the job has been to negotiate sites with little
more than a grid reference and reference pictures in inhospitable new cities on the fringes of boom or bust development. Scrambling his way up a half finished sky scrapper fire escapes with little more than a telephone number and the name of a contractor
called Zhou. In the summer of 2017 he relocated to London. He looks forward to shooting a very different type of architecture back home.
</div>
<div class="col span_1_of_4">
2 of 4
</div>
<div class="col span_1_of_4">
3 of 4
</div>
<div class="col span_1_of_4">
4 of 4
</div>
</div>
<div class="sticky group">
<div class="col span_1_of_4">
a of 4
</div>
<div class="col span_1_of_4">
b of 4
</div>
<div class="col span_1_of_4">
c of 4
</div>
<div class="col span_1_of_4">
d of 4
</div>
</div>
</div>
</div>
推荐阅读
- asp.net-core - 忽略 Swagger 中的 3rd 方控制器操作
- mysql - Jhipster 5.7.2 如何从 H2 迁移到 mysql 保留我的修改
- google-maps - 将 MapWinGIS 指向 URL 而不是 Tile 提供程序
- java - 可以删除 gradle init 文件吗?
- json - 将 JSON 序列化属性对象转换为键和值列表
- python - 涉及即时数据框对象的嵌套熊猫迭代
- javascript - 使用 createWriteStream 为通过 FTP 下载的 txt 文件分配变量
- c# - 当 Regex.NextMatch 为空时,程序卡在 NextMatch()
- sql - 同一表中不同列的多个唯一约束
- angular - Angular 7 RXjs 6.x - 如何使用 forkJoin(`of` 和 `Observable.create` 之间的区别)