How to slide nav bar from left instead from top?

前端 未结 9 1771
闹比i
闹比i 2020-12-02 18:49

Bootstrap supports toggling a navbar from the top. How can I slide it from the left when the screen-size is small?

For example:

In the screenshot pr

9条回答
  •  难免孤独
    2020-12-02 19:20

    Bootstrap 4 (update 2020)

    IMO the simplest way is to override the Bootstrap collapse animation so that it transitions from left to right (width instead of height). Instead of toggling display:block when .collapse.show is used, the Navbar is always display:block which enables you to position as needed and use transitions from both collapsing directions...

    Open menu: .collapse - .collapsing - .collapse.show
    Close menu: .collapse.show - .collapsing.show - .collapse

        .navbar-collapse {
            position: absolute;
            top: 54px;
            left: -100%;
            width: 100%;
            transition: all 0.4s ease;
            display: block;
            opacity: 0.8;
        }
        .navbar-collapse.collapsing {
            height: auto !important;
            left: -100%;
            margin-left: 1px;
            transition: all 0.2s ease;
            opacity: 0.9;
        }
        .navbar-collapse.show {
            margin-left: 100%;
            transition: all 0.2s ease;
            opacity: 1;
        }
    

    https://codeply.com/go/KSS4pjqtJy (full width)
    https://codeply.com/p/BvPCPA1wgZ (full height)

提交回复
热议问题