admin管理员组文章数量:1431726
I used bootstrap for my work. I have a bunch of menu-items on top of the page, around 15 items. Hence, my top menu doesn't adopt to the screen widths. It gets broken into the next line introduced by overflowing menus. I want to stop the menu overflow to the next line by having a "More" menu.
Idea is that the overflowing menu-items move to the "More" menu dropdown. But I don't know how to detect the menu overflow. How to move the extra menu-items into the "More" dropdown?
I do have a basic structure and markup in place.
Fiddle: /
Markup:
<ul class="nav nav-pills topnavi">
<li class="active" ><a href="#">Dashboard</a></li>
<li ><a href="#">Docs</a></li>
<li ><a href="#">Docs 2</a></li>
<li ><a href="#">Docs 3</a></li>
<li ><a href="#">Docs 4</a></li>
<li ><a href="#">Data</a></li>
<li ><a href="#">iWeb</a></li>
<li ><a href="#">Program</a></li>
<li ><a href="#">Config</a></li>
<!-- <li ><a href="#">Smart Inside</a></li>
<li ><a href="#">Settings </a></li>
<li ><a href="#">Account</a></li>
<li ><a href="#">Types</a></li>
<li ><a href="#">Notifications</a></li>
<li ><a href="#">History</a></li>
<li ><a href="#">Redmine</a></li>
<li ><a href="#">Logout</a></li> -->
<li class="dropdown" >
<a aria-expanded="false" aria-haspopup="true" role="button" href="#" data-toggle="dropdown" class="dropdown-toggle">
More <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li ><a href="#">Settings </a></li>
<li ><a href="#">Account</a></li>
<li ><a href="#">Types</a></li>
<li ><a href="#">Notifications</a></li>
<li ><a href="#">History</a></li>
<li ><a href="#">Redmine</a></li>
<li class="divider" role="separator"></li>
<li><a href="#">Logout</a></li>
</ul>
</li>
</ul>
CSS:
.topnavi {
margin-top:26px;
}
.nav-pills.topnavi > li > a {
border-radius: 4px 4px 0 0;
background:#f2f2f2;
padding: 8px 12px;
font-size:12px;
color: #727272;
border:1px solid #e7e7e7;
border-bottom:none;
}
.nav-pills.topnavi > li.active > a, .nav-pills.topnavi > li.active > a:focus, .nav-pills.topnavi > li.active > a:hover {
background-color: #d9d9d9;
color: #5b5b5b;
border: none;
}
.nav-pills.topnavi > li + li {
margin-left: 3px;
}
.dropdown-menu
{
right:0px !important;
left:auto;
}
I used bootstrap for my work. I have a bunch of menu-items on top of the page, around 15 items. Hence, my top menu doesn't adopt to the screen widths. It gets broken into the next line introduced by overflowing menus. I want to stop the menu overflow to the next line by having a "More" menu.
Idea is that the overflowing menu-items move to the "More" menu dropdown. But I don't know how to detect the menu overflow. How to move the extra menu-items into the "More" dropdown?
I do have a basic structure and markup in place.
Fiddle: http://jsfiddle/xFW8t/347/
Markup:
<ul class="nav nav-pills topnavi">
<li class="active" ><a href="#">Dashboard</a></li>
<li ><a href="#">Docs</a></li>
<li ><a href="#">Docs 2</a></li>
<li ><a href="#">Docs 3</a></li>
<li ><a href="#">Docs 4</a></li>
<li ><a href="#">Data</a></li>
<li ><a href="#">iWeb</a></li>
<li ><a href="#">Program</a></li>
<li ><a href="#">Config</a></li>
<!-- <li ><a href="#">Smart Inside</a></li>
<li ><a href="#">Settings </a></li>
<li ><a href="#">Account</a></li>
<li ><a href="#">Types</a></li>
<li ><a href="#">Notifications</a></li>
<li ><a href="#">History</a></li>
<li ><a href="#">Redmine</a></li>
<li ><a href="#">Logout</a></li> -->
<li class="dropdown" >
<a aria-expanded="false" aria-haspopup="true" role="button" href="#" data-toggle="dropdown" class="dropdown-toggle">
More <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li ><a href="#">Settings </a></li>
<li ><a href="#">Account</a></li>
<li ><a href="#">Types</a></li>
<li ><a href="#">Notifications</a></li>
<li ><a href="#">History</a></li>
<li ><a href="#">Redmine</a></li>
<li class="divider" role="separator"></li>
<li><a href="#">Logout</a></li>
</ul>
</li>
</ul>
CSS:
.topnavi {
margin-top:26px;
}
.nav-pills.topnavi > li > a {
border-radius: 4px 4px 0 0;
background:#f2f2f2;
padding: 8px 12px;
font-size:12px;
color: #727272;
border:1px solid #e7e7e7;
border-bottom:none;
}
.nav-pills.topnavi > li.active > a, .nav-pills.topnavi > li.active > a:focus, .nav-pills.topnavi > li.active > a:hover {
background-color: #d9d9d9;
color: #5b5b5b;
border: none;
}
.nav-pills.topnavi > li + li {
margin-left: 3px;
}
.dropdown-menu
{
right:0px !important;
left:auto;
}
Share
Improve this question
edited Nov 24, 2015 at 9:05
Abhitalks
28.5k5 gold badges61 silver badges81 bronze badges
asked Nov 24, 2015 at 7:07
Bhavan Kumar NatarajanBhavan Kumar Natarajan
3671 gold badge5 silver badges17 bronze badges
1 Answer
Reset to default 6I want to stop menu overflow next line by "More" menu.
You will have to collect extra list-items and push them into a separate list, depending on the width of the menu as pared to the total width of all menu items.
Deriving from this answer of mine (and adapting it for Bootstrap): https://stackoverflow./a/27450575/1355315
Markup:
Split the menu into two ul
s. One for the menu and one for the dropdown.
<div class="menuwrap">
<ul id="menu" class="nav nav-pills menu">
...<!-- This will contain all the menu items -->
</ul>
<ul class="nav nav-pills collect">
...<!-- This will contain the dropdown -->
</ul>
</div>
Javascript (jQuery) code fragment:
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
is the total width of all menu itemsctr
is the number of menu itemsfitCount
gets the number of menu items that exceed the menu width- Reset the width of all items which was zeroed in step #8
$collectedSet
collects all such items which exceed the menu width- Empty the dropdown menu and add the cloned collected items
- Set the width of original items to zero.
Here is a fiddle putting this all together: http://jsfiddle/abhitalks/y0ypz38w/
Note: This is good for small simple menus and a demo. For larger ones, it would be better to remove the menu items and move to the collected dropdown instead of cloning and changing the width. Also, it is not optimized and may throw up some problems in edge cases. Having gotten the idea, you can fine-tune it from here.
.
本文标签: javascriptBootstrap Menu with quotMorequot option Responsive issueStack Overflow
版权声明:本文标题:javascript - Bootstrap Menu with "More" option Responsive issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745568092a2663882.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论