Fixed sidebar navigation in fluid twitter bootstra

2019-01-03 19:25发布

Is it possible to make sidebar navigation stay always fixed on scroll in fluid layout?

7条回答
贼婆χ
2楼-- · 2019-01-03 20:10

I started with Andres' answers and ended up getting a sticky sidebar like this:

HTML:

<div class="span3 sidebar-width">
  <div class="well sidebar-nav-fixed">
    Sidebar
  </div>
</div>

<div class="span9 span-fixed-sidebar">
  Content
</div> <!-- /span -->

CSS:

.sidebar-nav-fixed {
  position:fixed;
}

JS/jQuery:

sidebarwidth = $(".sidebar-width").css('width');
$('.sidebar-nav-fixed').css('width', sidebarwidth);
contentmargin = parseInt(sidebarwidth) + 60;
$('.span-fixed-sidebar').css('marginLeft', contentmargin);

I'm assuming I also need JS to update the 'sidebarwidth' variable when the viewport is resized.

查看更多
登录 后发表回答