【问题标题】:Bootstrap 4 sticky-top not working properly [duplicate]Bootstrap 4粘顶无法正常工作[重复]
【发布时间】:2018-07-18 15:06:25
【问题描述】:

我需要让侧边栏贴在顶部。这在屏幕小于sm 断点时有效,但大于该断点时,它不会粘住。我认为罪魁祸首可能是类名的顺序,所以我尝试移动它们但结果相同。

sticky-top 可与 col-sm-* 一起使用,但不适用于 col-*。为什么?

我的代码在 HAML 和 SCSS 中,我希望没问题。 Refer to this pen

.container
  %ul.nav
    %li.nav-item
      %a.nav-link{:href => "#"}
        Menu
    %li.nav-item
      %a.nav-link{:href => "#"}
        Active
    %li.nav-item
      %a.nav-link{:href => "#"}
        Link
  .row
    .col-sm-3.sticky-top#sidebar
      This sidebar should stick to the top, both in expanded view and stacked view.
    .col-sm-9#main
      This main will continue scrolling until the bottom while the sidebar will stick to the top.
      This main will continue scrolling until the bottom while the sidebar will stick to the top.
      This main will continue scrolling until the bottom while the sidebar will stick to the top.
      This main will continue scrolling until the bottom while the sidebar will stick to the top.

CSS

html, body {
  margin: 0;
  height: 100%;
}

.container {
  height: 120%;
  box-shadow: 2px 2px 10px;

  .row {    
    > #sidebar {
      background:#ccc;
    }
    > #main {
      background: #eee;
    }
  }
}

【问题讨论】:

    标签: html css bootstrap-4


    【解决方案1】:

    #sidebar 与内容一样高,因此侧边栏没有空间可以修复...所以将.align-self-start 添加到您的#sidebar

    https://codepen.io/anon/pen/PQbLPR

    另见:https://getbootstrap.com/docs/4.3/utilities/flex/

    【讨论】:

    • 谢谢它的工作!这是否意味着sticky-top 只会坚持到我越过具有该类的元素的底部边框?
    • (^回答我自己的问题)是的,似乎是这样,因为我试图复制整个row,并且侧边栏一直卡到我到达第二行。谢谢!
    • 哇,谢谢。像魅力一样工作!
    猜你喜欢
    • 2019-04-11
    • 1970-01-01
    • 2018-04-24
    • 2021-07-26
    • 2019-08-08
    • 2020-01-09
    • 2017-11-17
    • 1970-01-01
    • 2017-07-13
    相关资源
    最近更新 更多