html - 使用 Bootstrap 的粘性右侧边栏

标签 html css twitter-bootstrap

<分区>

我正在尝试在 Bootstrap 中制作一个类似于 Facebook 的侧边栏。我试过使用“词缀”,但侧边栏的内容只是向左移动,与主要内容重叠。我试过添加“right:0;”,但它会溢出网格系统。

到目前为止,我的代码非常基础,因为开发依赖于这个固定的右侧边栏功能,但这里是:

<div class="container">
    <div class="row">
        <div class="col-md-9">
            A bunch of Lorem Ipsum text.
        </div>
        <div class="col-md-3 affix">
            <h1>Sticky sidebar</h1>
        </div>
    </div>
</div>

有人对如何使这项工作有任何建议吗?

谢谢!

最佳答案

body {
  background: pink;
}

.sticky {
  background: white;
  position: fixed;
  top: 0;
  right: 0;
}
<body>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
  <h1>Hi</h1>
</body>

<div class="sticky">
  <p>sticky sidebar</p>
  <p>sticky sidebar</p>
  <p>sticky sidebar</p>
  <p>sticky sidebar</p>
  <p>sticky sidebar</p>
  <p>sticky sidebar</p>
  <p>sticky sidebar</p>
  <p>sticky sidebar</p>
  <p>sticky sidebar</p>
  <p>sticky sidebar</p>
  <p>sticky sidebar</p>
</div>

你想要这样的东西吗?

您使用 css positon:fixed;top:0;right:0; 将 div 粘在右上角

关于html - 使用 Bootstrap 的粘性右侧边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43706556/

上一篇:css - 具有线性缓动动画的 CSS 中的缩放变换看起来变慢了?

下一篇:css - 带有 ng-repeat 的 ionic 卡,它们之间有空格

相关文章:

javascript - 更改后退按钮指向的位置

jquery - 带有奇数/偶数行的 jquery Accordion 的第 n 个子问题

javascript - 在 Angular 2 中使用 HTML5 主题

javascript - 如何在表中激活 Bootstrap 日期选择器?

javascript - 上一个和下一个按钮在网页中不起作用

javascript - 使 div 填充屏幕的 100% 高度

html - 类似于网格的div布局

html - 悬停时转换 div 时导航弹跳

javascript - 底部的 Owl Carousel 进度条?

html - 使用 Bootstrap 使搜索输入宽度为 100%