0

How can I fix Bootstrap col.

I tried like this but it is not working:

<div class="row">
    <div class="col-md-6">Content goes here...</div> 
    <div class="col-md-6" style=" position: fixed">Content goes here...</div> 
</div>

fixed position makes col as absolute position.

And how can I disable a fixed position, when the page is scrolled down from top 400px.

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
mat7777
  • 37
  • 1
  • 7

1 Answers1

0

Use media query to only apply the fixed position above a specific screen width. For example 768px is the Bootstrap 4 md breakpoint:

CSS (min-height is optional):

@media (min-width: 768px) {
    .fixed-posi {
        width: 50%;
        margin-left: 50%;
        min-height:100%;
        position:fixed;
    }
}

Then, use fixed-posi in the layout like this...

   <div class="row">
        <div class="col-md-6">
           Content goes here...
        </div>
        <div class="col-md-6 fixed-posi">Content goes here... (fixed position)
        </div>
   </div>

Demo: https://www.codeply.com/go/751CygARyO

Similar question (fixed DIV on left): How to left column fixed and right scrollable in Bootstrap 4, responsive?

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624