简体   繁体   English

使用引导程序 4 css 显示固定在左侧的列和右侧可滚动的另一列

[英]Displaying a col fixed on left and the other col on the right scrollable using bootstrap 4 css

I have a bootstrap row where I have 2 cols inside it.我有一个引导行,里面有 2 个列。 I need 1 col to be on the left side which should be sticky.我需要 1 col 在左侧,应该是粘性的。 The col on the right side, I have multiple cards rendered there which contain text and those cards should be scrollable.右侧的 col,我在那里渲染了多张包含文本的卡片,这些卡片应该是可滚动的。

在此处输入图像描述

See the image, The cards like Article and Post should be fixed to that position, but the posts on the right should be scrollable.看图片,文章和帖子之类的卡片应该固定到那个position,但是右边的帖子应该是可滚动的。

The code I have written is this,我写的代码是这样的,

<div class="container-fluid">
  <div class="row">

    // Row 1 should be on the left
    <div class="col-md-3">
      <app-articles></app-articles>
      <app-navigation></app-navigation>
    </div>


    // Row 2 should be on the right
    <div class="col-md-9">
      <div class="card" *ngFor="let post of posts; let i = index"></div>
    </div>

  </div>
</div>

How do I do this?我该怎么做呢?

If you are using bootstrap 5 then bootstrap by default provide class for same ie sticky-top如果您使用的是引导程序 5,则引导程序默认为相同的即粘顶提供 class

 <div class="container-fluid">
    <div class="row">
     // Row 1 should be on the left
      <div class="col-md-3">
        <div class="sticky-top">
          <app-articles></app-articles>
          <app-navigation></app-navigation>
        </div>
      </div>

    // Row 2 should be on the right
    <div class="col-md-9">
      <div class="card" *ngFor="let post of posts; let i = index"></div>
    </div>
  </div>
</div>

And if you want to fixed position then replaced the class with fixed-top, but you have to look for alignment while using position fixed, for more information regarding to position classes then refer to the official bootstrap 5 documentations. And if you want to fixed position then replaced the class with fixed-top, but you have to look for alignment while using position fixed, for more information regarding to position classes then refer to the official bootstrap 5 documentations. https://getbootstrap.com/docs/5.2/helpers/position/ https://getbootstrap.com/docs/5.2/helpers/position/

Hope that work for you:)希望对你有用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用bootstrap col时图像周围左右空白 - White space left and right around images when using bootstrap col css 2列左固定仅按图像宽度,右列占用容器的其余宽度 - css 2 column left fixed-only-by-image-width, right col to take up rest of container width 删除 col-md-6 Bootstrap 上的左/右填充 - removing left/right padding on col-md-6 Bootstrap #Bootstrap /我想将col-md-3放在左边,将col-md-9放在右边,但是失败了 - #Bootstrap/ I want to put col-md-3 at left and col-md-9 at right but failed 在bootstrap col内固定图像 - fixed image inside bootstrap col Bootstrap数据固定/位置固定的col与其他col重叠 - Bootstrap data-affix/position-fixed col overlapping other col 如何使用col-sm-3在Bootstrap中向网格的左侧和右侧添加填充而无需在网格框之间填充 - How to add padding to the left and right side of grid in Bootstrap WITHOUT padding between grid boxes using col-sm-3 带Bootstrap 4的CSS Grid:将`col-auto`和`col`与fr单元一起使用时的布局问题 - CSS Grid with Bootstrap 4: layout problem when using `col-auto` and `col` with fr unit 如何使用 css 将 bootstrap class col-md-10 更改为 div 的 col-md-12 - how to change bootstrap class col-md-10 into col-md-12 of div using css 始终居中的 Bootstrap 响应式固定宽度列 - Bootstrap responsive fixed width col that is always centered
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM