简体   繁体   English

Bootstrap 5:如何在最右边对齐导航折叠切换但在小型设备上仍然向下折叠?

[英]Bootstrap 5: how to align nav collapse toggle at the very right but collapsible still downwards on small devices?

I'd like to have an always visible on all devices nav section and the collapse toggle aligned to the right .我想要一个在所有设备上始终可见的导航部分,并且折叠切换开关与右侧对齐

Now if putting the collapse toggle after the <div class="collapse navbar-collapse... in Bootstrap 5.2 , the collapsible collapses upwards, moving all the content / elements - after it - downwards like this: https://jsfiddle.net/qavsom61/1/现在,如果在Bootstrap 5.2中将折叠开关放在<div class="collapse navbar-collapse... ... /qavsom61/1/

If I put the toggle code before the <div class="collapse... like in the original bootstrap example , the expanded collapsible nav is now aligned to the right instead of the left which I don't want.如果我将切换代码放在<div class="collapse...之前,就像在原始引导程序示例中一样,展开的可折叠导航现在会向右对齐,而不是我不想要的向左对齐。

Is there any "smooth" solution to it?有什么“平滑”的解决方案吗? Thx in advance!!提前致谢!

As said and as you can see on fiddle above I'd like to have an always visible nav section positioned on the right side.如前所述,正如您在上面的小提琴上看到的那样,我希望在右侧放置一个始终可见的导航部分。 And another horizontal nav aligned to the left on large devices which collapses down vertically on small devices .另一个水平导航在大型设备上向左对齐,在小型设备上垂直向下折叠。

The only thing I could think of was to create 2 navbar-nav clones one for large devices above the toggle and one below the toggle for small devices .我唯一能想到的是创建 2 个 navbar-nav 克隆,一个用于切换开关上方的大型设备,一个用于小型设备的切换开关下方。 But despite not being as smooth (#clones) there are some other issues.但是,尽管没有那么顺利(#clones),但还有一些其他问题。 like both the navs are aligned left on large devices no matter what I've tried so far?: Take a look here: https://jsfiddle.net/aw9z7jmr/就像两个导航在大型设备上都左对齐,无论我到目前为止尝试了什么?:看看这里: https://jsfiddle.net/aw9z7jmr/


[EDIT] I just played around and found a not so pleasant solution based on my "clone" approach above. [编辑] 我只是四处游玩,并根据上面的“克隆”方法找到了一个不太令人愉快的解决方案。 So if anyone got a better solution let me know please!因此,如果有人有更好的解决方案,请告诉我!

I added flex-fill to <ul class="navbar-nav ms-0 me-auto d-none d-lg-flex flex-fill">我将flex-fill添加到<ul class="navbar-nav ms-0 me-auto d-none d-lg-flex flex-fill">

but I had to modify the flex-fill class like this但我不得不像这样修改 flex-fill class

.navbar .flex-fill {flex: 100 1 auto !important;}

https://jsfiddle.net/2orp39sh/ https://jsfiddle.net/2orp39sh/

remove " navbar-expand-lg " in nav tag删除nav标签中的“ navbar-expand-lg

and d-lg-none in navbar-collapsed-lg-nonenavbar-collapse

https://jsfiddle.net/2r7oy0bj/2/ https://jsfiddle.net/2r7oy0bj/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM