Making rightmost column fixed position in Bootstrap 4

1867 views javascript
-1

I'm trying to have the right column in Bootstrap 4 grid system fixed using position: fixed.

Here's a demo and it's code.

I want the button group on the right to stick to the viewport when I scroll the document. I have tried adding position: fixed; this doesn't work as intended - it causes the button group to overlay on top of the window like this.

I have already seen this answer on making columns fixed in Bootstrap, but the solutions won't work when the position of the columns is interchanged. Few of the solutions there will cause the right column to overlay on top of the left column in small screens, which is undesirable. In such cases, when viewed on small screens, I want the columns to be stacked (with the sticky feature disabled).

I prefer CSS solutions but if possible, I'd also like to know how it's done in JS.

answered question

1 Answer

6

Place your buttons inside another div and then add a style of position: fixed to that div like so:

<div class="col-md-3" align="center" style="margin-bottom: 40px;/* position: fixed; */">
  <div style="position: fixed;">
    <button class="btn btn-success btn-custom">
    <span>Button 1</span>
    </button>
    <br>
    <button class="btn btn-warning btn-custom">
    <span>Button 2</span>
    </button>
    <button class="btn btn-danger btn-custom">
    <span>Button 3</span>
    </button>
  </div>
</div>

You can make the style a css class and make it show only on big screens

posted this

Have an answer?

JD

Please login first before posting an answer.