I want to stop the menu overflow in the next line of the "Advanced" menu.
You will have to collect additional list items and insert them into a separate list depending on the width of the menu compared to the total width of all menu items.
Having received this answer (and adapted it for Bootstrap): fooobar.com/questions/1236673 / ...
Markup:
Divide the menu into two ul s. One for the menu and one for the dropdown menu.
<div class="menuwrap"> <ul id="menu" class="nav nav-pills menu"> ... </ul> <ul class="nav nav-pills collect"> ... </ul> </div>
Javascript code snippet (jQuery):
function collect() { elemWidth = $menu.width(); fitCount = Math.floor((elemWidth / varWidth) * ctr) - 1; $menu.children().css({"display": "block", "width": "auto"}); $collectedSet = $menu.children(":gt(" + fitCount + ")"); $("#submenu").empty().append($collectedSet.clone()); $collectedSet.css({"display": "none", "width": "0"}); }
Where:
$menu.width() gets the width of the menuvarWidth - total width of all menu itemsctr - number of menu itemsfitCount gets the number of menu items exceeding the width of the menu- Reset the width of all elements that were reset to zero in step # 8
$collectedSet collects all such items that exceed the width of the menu- Clear the dropdown menu and add the cloned collected items.
- Set the width of the source elements to zero.
Here is a fiddle combining all of this: http://jsfiddle.net/abhitalks/y0ypz38w/
Note. This is useful for small simple menus and demos. For larger ones, it would be better to delete the menu items and go to the assembled drop-down list instead of cloning and changing the width. In addition, it is not optimized and may cause some problems in the case of edges. Once you get this idea, you can customize it here.
.
source share