首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有简单侧边栏的粘性页脚

带有简单侧边栏的粘性页脚
EN

Stack Overflow用户
提问于 2014-10-04 03:53:31
回答 1查看 161关注 0票数 0

我有一台sidebar I'm using from startbootstrap。我正尝试在页面底部添加一个粘性页脚。但是,当我切换导航栏时,页脚会跳到顶部。

代码语言:javascript
复制
<div id="wrapper" ng-class="{'toggled': hidden }">
  <div ng-include='"views/nav.html"'></div>
  <div id="page-content-wrapper">
    <div class="container-fluid">
      <div class="row" id='main-body'>
        <div class="col-lg-12">
          <div ui-view=''></div>
        </div>
      </div>

      <footer id='sticky-footer'>
        <p class='text-muted'>The source for this website is <a href='http://github.com/jasonshark/jasonshark.github.io'>available on Github</a></p>
      </footer>
    </div>
</div>

其中nav.html看起来像:

代码语言:javascript
复制
<div id="sidebar-wrapper">
    <ul class="sidebar-nav">
        <li class="sidebar-brand"><a href="/">Connor Leech</a></li>
        <li><a href='/'>Home</a></li>
        <li><a ui-sref='resume'>Resume</a></li>
        <li><a ui-sref='portfolio'>Portfolio</a></li>
        <li><a ui-sref='timeline'>Timeline</a></li>
    </ul>
</div>

<button class='btn btn-default btn-lg inverse' ng-click='hideMenu()'>
    <span class='glyphicon glyphicon-align-justify'></span>
</button>

我添加了这些样式来将页脚移到底部:

代码语言:javascript
复制
#sticky-footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}

以下是切换侧边栏的样式:

代码语言:javascript
复制
#wrapper {
    padding-left: 0;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
}

#wrapper.toggled {
    padding-left: 250px;
}

#sidebar-wrapper {
    z-index: 1000;
    position: fixed;
    left: 250px;
    width: 0;
    height: 100%;
    margin-left: -250px;
    overflow-y: auto;
    background: #000;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
}

#wrapper.toggled #sidebar-wrapper {
    width: 250px;
}

#page-content-wrapper {
    width: 100%;
    padding: 15px;
}

#wrapper.toggled #page-content-wrapper {
    position: absolute;
    margin-right: -250px;
}

当我们单击菜单时,有一小段angular.js可以添加或删除.toggled类。即使在导航菜单向左滑动的情况下,如何才能使页脚停留在底部?

EN

回答 1

Stack Overflow用户

发布于 2014-10-04 05:17:03

对粘性脚注使用固定位置,而不是绝对,我没有加载您的代码,但可能就是这样。

摘自http://www.w3schools.com/css/css_positioning.asp

固定位置:具有固定位置的元素相对于浏览器窗口进行定位。

绝对定位:绝对位置元素相对于具有非静态位置的第一个父元素进行定位。如果找不到这样的元素,则包含块为:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26185841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档