【问题标题】:Sticky header scrolls away after some scrolling on bootstrap V4.4.1在引导程序 V4.4.1 上滚动后,粘性标题会滚动
【发布时间】:2020-08-25 13:57:51
【问题描述】:

我正在尝试制作带有粘性顶部和粘性底部的卡片,因为它们显示了一些我希望始终显示的信息和输入。问题是滚动里面的一些内容后,顶部消失了,我不希望这样。

我发现在移除卡片页脚或设置自动卡片高度后问题就消失了。问题是,如果屏幕尺寸足够大,我想要定位的位置需要特定的高度。也无法删除页脚,因为它有内容。

我尝试将便签移到卡体之外,但在移动设备上,它们会在滚动的王国中消失...

我在其他问题上找到的答案并不是很有帮助,因为许多问题都是针对粘性页脚并且没有尝试将粘性页脚放入引导卡中

.sticky-top {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  height: 30px;
  background: red
}

.sticky-bottom {
  position: -webkit-sticky;
  position: sticky;
  bottom: 0;
  height: 30px;
  background: lightblue;
}

.the-problem {
  height: 30px
}

.content {
  height: 600px;
  background: gray
}

#thing {
  height: 200px;
  width: 300px;
  overflow: auto;
}

#thing {
  width: 300px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<form id="thing" class="card mt-3">
  <div class="card-header">An unimportant title</div>
  <div class="card-body p-0" style="overflow: initial">
    <div class="sticky-top">
      sticky-top
    </div>

    <div class="content"> Some content </div>

    <div class="sticky-bottom">
      sticky-bottom
    </div>
    <div class="card-footer the-problem px-3">

    </div>
  </div>
</form>


<form id="thing2" class="card mt-3">
  <div class="card-header">An unimportant title</div>
  <div class="card-body p-0" style="overflow: initial">
    <div class="sticky-top">
      sticky-top
    </div>

    <div class="content"> Some content </div>

    <div class="sticky-bottom">
      sticky-bottom
    </div>
    <div class="card-footer the-problem px-3">

    </div>
  </div>
</form>

【问题讨论】:

    标签: html css bootstrap-4 sticky bootstrap-cards


    【解决方案1】:

    需要 2 处更改...

    • 评论了粘性页脚下的 div... 这样页脚就可以很好地粘在底部了
    • 分隔&lt;form&gt;.card 类,这样固定高度不在.card div 元素上...这是因为如果父级具有固定高度,粘性就会消失 - 我们需要这样做&lt;form&gt; 这个固定高度还在&lt;form&gt;

    工作sn-p如下:

    .sticky-top {
      position: -webkit-sticky;
      position: sticky;
      top: 0;
      height: 30px;
      background: red
    }
    
    .sticky-bottom {
      position: -webkit-sticky;
      position: sticky;
      bottom: 0;
      height: 30px;
      background: lightblue;
    }
    
    .the-problem {
      height: 30px
    }
    
    .content {
      /* height: 600px; */
      background: gray
    }
    
    #thing {
      height: 200px;
      width: 300px;
      overflow: auto;
    }
    
    #thing {
      width: 300px;
    }
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
    <form id="thing">
      <div class='card mt-3'>
        <div class="card-header">An unimportant title</div>
        <div class="card-body p-0" style="overflow: initial">
          <div class="sticky-top">
            sticky-top
          </div>
    
          <div class="content">
            <p> let the actual content occupy the eeded space... </p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
            nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
            laborum.
          </div>
    
          <div class="sticky-bottom">
            sticky-bottom
          </div>
          <!--    <div class="card-footer the-problem px-3">    </div> -->
        </div>
      </div>
    </form>

    【讨论】:

    • 阅读这篇文章让我意识到我错误地编码了 sn-p 所以它看起来像其他粘性页脚问题......卡片不可滚动,卡片主体是。然而,将表格和卡片与表格保持高度分开解决了我的实际问题,结果证明这与我提出的问题无关......将其标记为我发布的问题的答案,但卡片的细节很小-footer 不应该被删除
    猜你喜欢
    • 2016-04-30
    • 2020-07-14
    • 2019-08-18
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    • 2020-10-15
    • 2019-07-27
    相关资源
    最近更新 更多