html - 添加限制以修复侧边栏

标签 html css

我创建了一个带有菜单的修复侧边栏。我的问题是它与我的页脚重叠。我希望它在页脚之前停止。这是我的代码。

HTML

    <div class="maincontent">
    main content here
</div>
    <div id="leftCol">
                    <ul class="nav nav-stacked" id="sidebar">
                      <li>menu1</li>
                      <li>menu2</li>
                    </ul>
    </div>

<footer id="mainfooter"></footer>

对于CSS

.affix-top,.affix{
  position: static;
}
@media (min-width: 979px) {
  #sidebar.affix-top {
    position: static;
    margin-top:30px;
  }

  #sidebar.affix {
    position: fixed;
    top:70px;
  }
}

#sidebar li.active {
    border:0 #eee solid;
    border-right-width:4px;
}
#page-wrap { 
  margin: 15px auto; 
  position: relative; 
}

#sidebar {
  position: fixed; 
  margin-left: 10px; 
}

和js

$('#sidebar').affix({
      offset: {
        top: 245
      }
});

社区非常感谢任何回答。

最佳答案

您可以根据窗口大小使用 jQuery 为侧边栏添加高度。

在js中添加

function setHeight(){
var winHeight = $(window).height();
$("#sidebar").css("height", winHeight - yourFooterHeight);
}

在CSS中添加

#sidebar{overflow:auto;}

在你的body标签中调用js函数

onresize="setHeight()" onload="setHeight()"

关于html - 添加限制以修复侧边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27506010/

相关文章:

html - 为什么添加旋转动画会偏移我的图像?

javascript - 如何避免网页上的第一个函数调用花费这么长时间?

html - 是否可以在忽略不透明层的同时使用 mix-blend-mode 模糊背景?

Javascript 优化

css - 这个 nth-child 选择器在 IE 8 中如何工作?

php - 数据库文本在 PHP while 循环中打印两次

javascript - 多幻灯片 Owl Carousel 上的动画

javascript - 有什么方法可以从 indexeddb 中检索随机行

html - 适合对象 : contain; Calculate even height based on width percentage %?

html - flexbox 可以检测到 flex 元素何时换行吗?