【发布时间】:2017-05-02 08:10:46
【问题描述】:
我正在尝试制作一个粘性页脚,但由于某种原因它正在播放。 当我在其中一个上设置页脚时,我有几页具有不同内容高度的页面,它会破坏其他页面。 如何为所有页面创建全局样式,以便在页面底部有一个粘性页脚,并且如果不需要它还删除任何滚动,因为我的某些页面需要滚动才能到达页脚,而内容大约有高度。
当我使用一个名为 screen-fly 的网站来测试我的网站以在所有屏幕尺寸上进行测试时,我需要一个能够保证在任何屏幕尺寸上进行响应式设计的解决方案。
我的代码在 plunker 上可用,但是我进行了很多研究并尝试了一些样式解决方案。这是其中的两个
解决方案 1:-
/* **************************************************/
/* One solution */
html, body {
height:100%;
min-height:100%;
}
/* navigation style*/
.navbar-brand {
margin: 0 auto;
color:white;
}
.navbar-inverse {
background: rgb(14, 78, 114);
}
.navbar-inverse .navbar-nav>li>a {
color: #8EE8CD;
}
/* Content style*/
.container.content {
margin-top: 100px;
}
/* footer style*/
.wrapper {
position:relative;
min-height:100%;
}
footer {
text-align: center;
position:absolute;
bottom:0px;
width:100%;
color: white;
background-color: rgb(14, 78, 114);
}
溶液 2:-
/* Another solution */
html, body {height: 100%;}
#wrap {min-height: 100%;}
#main {overflow:auto;
padding-bottom: 150px;} /* must be same height as the footer */
#footer {position: relative;
margin-top: -150px; /* negative value of footer height */
height: 150px;
clear:both;}
/*Opera Fix*/
body:before {
content:"";
height:100%;
float:left;
width:0;
margin-top:-32767px;
}
这里是代码的一些链接。
plunker 编辑器:Plunker Editor
plunker 全屏:Plunker Full Screen
我在 screenfly 上的网站:Screenfly Site
【问题讨论】:
-
你试过
display: fixed; bottom: 0; left: 0; right: 0;吗? -
将
.container.content {margin-top: 100px;}更改为.container.content {padding-top: 100px;} -
非常感谢这里的每一个人,你们真的是一个非常有帮助的社区,但是,Saurav Rastogi 给出了一个非常简单的答案,因为我之前没有使用过 flexbox(一定会看看)我也要感谢 Neil Smith 和 SvenL。
标签: html css twitter-bootstrap responsive-design footer