【问题标题】:How to left column fixed and right scrollable in Bootstrap 4, responsive?如何在 Bootstrap 4 中将列固定和右滚动,响应式?
【发布时间】:2017-10-20 12:50:19
【问题描述】:

我正在使用 Angular 4、Bootstrap 4 并尝试实现一个固定的可滚动右 div 和一个固定的左 div。它应该与Trulia 所拥有的非常相似。

Bootstrap 在版本 4 中删除了 Affix jQuery 插件,因此此方法不再有效,他们建议使用 position:sticky,但我无法让它工作。

请帮忙!

index.html

<div class="container-fluid">
  <div class="row h-100">
    <div class="col-md-6">
      <div id="left-container">
        <div class="search-property">
          <input type="text">
        </div>
      </div>
    </div>
    <div class="col-md-6">
      <div id="right-container">
        <app-home-right></app-home-right>
      </div>
    </div>  
  </div>
</div>

style.css

#left-container {
  height: 100%;

  position: fixed;
  width: inherit; 
}

#right-container {
  position: absolute;
}

.search-property {
  position: relative;
  top: 50%;
  transform: perspective(1px) translateY(-50%);
  margin-left: 50%;
}

.nopadding {
   padding: 0 !important;
   margin: 0 !important;
}

.border {
  border: 1px solid black;
}

【问题讨论】:

    标签: twitter-bootstrap sticky bootstrap-4 twitter-bootstrap-4


    【解决方案1】:

    我不确定您是否只是想要一个具有 1 个固定边的布局,还是要固定边直到它到达页脚(如 Trulia)。这是一个左侧固定的简单布局(Split 50 50)。

    body, html {
        height: 100%;
    }
    
    #left {
        position: fixed;
        top: 0;
        bottom: 0;
    }
    

    要使侧面仅在特定点固定(或粘滞),position:sticky 在所有浏览器中都不能很好地工作。我会使用插件或 polyfill,如下所述:How to use CSS position sticky to keep a sidebar visible with Bootstrap 4

    https://codeply.com/go/IuOp3nvCpy

    更新 Bootstrap 4.0.0 - fixed-top 类现在位于 Bootstrap 中,可以在左侧列中使用它来删除 position:fixed 所需的额外 css。

    更新 Bootstrap 4.1 - h-100 类现在可用,它消除了 height:100% 所需的额外 CSS:https://codeply.com/go/ySC2l4xcEi

    响应式 - 如 cmets 中所述,媒体查询可用于使布局响应式:https://codeply.com/go/pqzJB4thBY


    相关:
    [右侧固定 col](https://stackoverflow.com/questions/48972833/bootstrap-col-fixed-position/48974617#48974617)
    https://stackoverflow.com/questions/40497288/how-to-create-a-fixed-sidebar-layout-with-bootstrap-4/49436717#49436717

    【讨论】:

    • 我将在左侧有一个搜索表单,我需要这个响应式(在移动设备上位于右侧 div 的顶部)。我该怎么做?
    • 使用列上的网格类和媒体查询仅应用较大宽度的固定值,如下所示:codeply.com/go/pqzJB4thBY
    • 反响很好。
    猜你喜欢
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2019-02-20
    • 2018-11-15
    • 2018-11-28
    • 2019-06-14
    • 2019-07-27
    相关资源
    最近更新 更多