Make column fixed position in bootstrap

后端 未结 7 877
南方客
南方客 2020-11-29 20:39

Using Bootstrap, I have a grid column class=\"col-lg-3\" that I want to place it in position:fixed while the other .col-lg-9 is normal position (scroll-able through the page

相关标签:
7条回答
  • 2020-11-29 21:20

    Use this, works for me and solve problems with small screen.

    <div class="row">
        <!-- (fixed content) JUST VISIBLE IN LG SCREEN -->
        <div class="col-lg-3 device-lg visible-lg">
           <div class="affix">
               fixed position 
            </div>
        </div>
        <div class="col-lg-9">
        <!-- (fixed content) JUST VISIBLE IN NO LG SCREEN -->
        <div class="device-sm visible-sm device-xs visible-xs device-md visible-md ">
           <div>
               NO fixed position
            </div>
        </div>
           Normal data enter code here
        </div>
    </div>
    
    0 讨论(0)
  • 2020-11-29 21:21

    Updated for Bootstrap 4

    Bootstrap 4 now includes a position-fixed class for this purpose so there is no need for additional CSS...

    <div class="container">
        <div class="row">
            <div class="col-lg-3">
                <div class="position-fixed">
                    Fixed content
                </div>
            </div>
            <div class="col-lg-9">
                Normal scrollable content
            </div>
        </div>
    </div>
    

    https://www.codeply.com/go/yOF9csaptw

    0 讨论(0)
  • 2020-11-29 21:24

    With bootstrap 4 just use col-auto

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-auto">
                Fixed content
            </div>
            <div class="col-sm">
                Normal scrollable content
            </div>
        </div>
    </div>
    
    0 讨论(0)
  • 2020-11-29 21:25
    <div class="row">
        <div class="col-lg-3">
           <div class="affix">
               fixed position 
            </div>
        </div>
        <div class="col-lg-9">
           Normal data enter code here
        </div>
    </div>
    
    0 讨论(0)
  • 2020-11-29 21:25

    iterating over Ihab's answer, just using position:fixed and bootstraps col-offset you don't need to be specific on the width.

    <div class="row">
        <div class="col-lg-3" style="position:fixed">
            Fixed content
        </div>
        <div class="col-lg-9 col-lg-offset-3">
            Normal scrollable content
        </div>
    </div>
    
    0 讨论(0)
  • 2020-11-29 21:28

    in Bootstrap 3 class="affix" works, but in Bootstrap 4 it does not. I solved this problem in Bootstrap 4 with class="sticky-top" (using position: fixed in CSS has its own problems)

    code will be something like this:

    <div class="row">
        <div class="col-lg-3">
            <div class="sticky-top">
                Fixed content
            </div>
        </div>
        <div class="col-lg-9">
            Normal scrollable content
        </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题