How to create a fixed sidebar layout with Bootstrap 4?

前端 未结 5 1280
执笔经年
执笔经年 2020-12-02 14:40

I\'m trying to create a layout like the screenshot using Bootstrap 4 but I\'m having some problems with making the sidebar fixed and achieving this layout at the sa

5条回答
  •  Happy的楠姐
    2020-12-02 14:45

    I'm using the J.S. to fix a sidebar menu. I've tried a lot of solutions with CSS but it's the simplest way to solve it, just add J.S. adding and removing a native BootStrap class: "position-fixed".

    The J.S.:

    var lateral = false;
    function fixar() {
    
                var element, name, arr;
                element = document.getElementById("minhasidebar");
    
                if (lateral) {
                    element.className = element.className.replace(
                            /\bposition-fixed\b/g, "");
                    lateral = false;
                } else {
    
                    name = "position-fixed";
                    arr = element.className.split(" ");
                    if (arr.indexOf(name) == -1) {
                        element.className += " " + name;
                    }
                    lateral = true;
                }
    
            }
    

    The HTML:

    Sidebar:

    
    

提交回复
热议问题