Bootstrap 5使用宽度折叠,而不是从隐藏转换

bybem2ql  于 2024-01-04  发布在  Bootstrap
关注(0)|答案(1)|浏览(124)

我尝试使用BS 5折叠组件,但使用宽度而不是高度。
我修改了元素.collapsing,使用width代替height:

#sidebar {
    width: 15rem;
}

#sidebar.collapsing {
    width: 0;
    height: auto;
    transition: width 0.35s ease;
}

字符串
当元素被隐藏的时候,这个效果很好。它显示了一个平滑的隐藏动画。但是,当显示元素的时候,根本没有动画。
下面是一个完整的代码示例:
https://jsfiddle.net/v72p0azg/
点击汉堡包图标来展开/折叠侧边栏。正如你所看到的,折叠时它工作得很好,但是展开时它没有过渡。

szqfcxe2

szqfcxe21#

您还需要在普通的#边栏中添加过渡。
试试这个.

#sidebar {
    width: 15rem;
    transition: width 0.35s ease;
}

#sidebar.collapsing {
    width: 0;
    height: auto;
    transition: width 0.35s ease;
    }

字符串

相关问题