Bootstrap Nested Dropdown on Rails - html

I am trying to create a cascading view in dropdown menu ->
/myApp/app/views/layouts/includes/_site-header.html.erb
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Level 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><%= link_to "Level 1.0.1", "/some_link/link_level_1_0_1" %></li>
<li class="dropup"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Level1.1<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><%= link_to "Level 1.1", "/some_link/link_level_1_1_1" %></li>
</ul>
</li>
</ul>
</li>
Level 1 (top most level) shows up correct, but Level 1.1 nested dropdown, not shows.
How can I use inline CSS to correct this?

You want to make it Nested Dropdown. Here is really good example.
JSFIDDLE
Source from http://jsfiddle.net/chirayu45/yxkut/16/
HTML:
<div class="dropdown" style="position:relative">
Click Here <span class="caret"></span>
<ul class="dropdown-menu">
<li>
<a class="trigger right-caret">Level 1</a>
<ul class="dropdown-menu sub-menu">
<li>Level 2</li>
<li>
<a class="trigger right-caret">Level 2</a>
<ul class="dropdown-menu sub-menu">
<li>Level 3</li>
<li>Level 3</li>
<li>
<a class="trigger right-caret">Level 3</a>
<ul class="dropdown-menu sub-menu">
<li>Level 4</li>
<li>Level 4</li>
<li>Level 4</li>
</ul>
</li>
</ul>
</li>
<li>Level 2</li>
</ul>
</li>
<li>Level 1</li>
<li>Level 1</li>
</ul>
</div>
JS:
$(function(){
$(".dropdown-menu > li > a.trigger").on("click",function(e){
var current=$(this).next();
var grandparent=$(this).parent().parent();
if($(this).hasClass('left-caret')||$(this).hasClass('right-caret'))
$(this).toggleClass('right-caret left-caret');
grandparent.find('.left-caret').not(this).toggleClass('right-caret left-caret');
grandparent.find(".sub-menu:visible").not(current).hide();
current.toggle();
e.stopPropagation();
});
$(".dropdown-menu > li > a:not(.trigger)").on("click",function(){
var root=$(this).closest('.dropdown');
root.find('.left-caret').toggleClass('right-caret left-caret');
root.find('.sub-menu:visible').hide();
});
});

Related

jQuery ul li trees - slideToggle only li with ul child

I know there are a lot of similar solutions.. This one almost works :)
I have an unsorted list:
<ul id="Tree" class="sub-menu">
<li class="folder">First level
<ul class="sub-menu">
<li>File 1.1</li>
<li class="folder">Second level
<ul class="sub-menu">
<li>File 2.1</li>
<li>File 2.2</li>
<li class="folder">Tretji nivo
<ul class="sub-menu">
<li>File 3.1</li>
<li>File 3.2</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
And the jQuery:
$('.folder').click(function(event) {
event.stopPropagation();
$(this).find('>.sub-menu').slideToggle();
});
Click on .folder works as desired. The problem is that the slideToggle is triggered on all li elements. So if I click on a li > a element the file is downloaded but the ul is toggled also. I want to prevent toggle when I click on an element that has no direct ul child.
You could add the folder class to the level text instead of the whole li tag :
$('.folder').click(function(event) {
event.stopPropagation();
$(this).next('.sub-menu').slideToggle();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="Tree" class="sub-menu">
<li><span class="folder">First level</span>
<ul class="sub-menu">
<li>File 1.1</li>
<li><span class="folder">Second level</span>
<ul class="sub-menu">
<li>File 2.1</li>
<li>File 2.2</li>
<li><span class="folder">Tretji nivo</span>
<ul class="sub-menu">
<li>File 3.1</li>
<li>File 3.2</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

How to apply Bootstrap Sidebar & Sidebar collapse Menu

How to apply Bootstrap Sidebar & Sidebar collapse Menu
<ul class="nav nav-sidebar">
<li>
<a data-toggle="collapse" href="#collapseTwo" aria-expanded="true" data-parent="#accordion" >
<i class="glyphicon glyphicon-info-sign"></i>
About Us
</a>
</li>
<li>
<ul id="collapseTwo" class="collapse">
<li>
Quote
</li>
<br/>
<li>
About Us Page Content
</li>
</ul>
</li>
</ul>
so How to apply Bootstrap Sidebar & Sidebar only collapse Menu
try this code
html
<ul id="nav">
<li>Home</li>
<li>Products [+]
<ul>
<li>All Products</li>
<li>Product1 [+]
<ul>
<li>Product1</li>
</ul>
</li>
<li>Product2 [+]
<ul>
<li>Product2</li>
</ul>
</li>
</ul>
</li>
<li>Services [+]
<ul>
<li>Service 1</li>
<li>Service 2</li>
<li>Service 3</li>
</ul>
</li>
<li>Support</li>
<li>Contact</li>
</ul>
demo

Bootstrap dropdown tabmenu

I am using the bootstrap tabmenu but now I want to make it a dropdown menu. I know that bootstrap have native support for this but I want the dropdown to be toggled only if the caret is clicked, if the rest of the menu item area are clicked that should work as an ordinary link. Do anyone know how to do this?
Here is what the code looks like today
jsfiddle-example
<div class="container">
<ul class="nav nav-tabs">
<li class="active">Home</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Menu 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Submenu 1-1</li>
<li>Submenu 1-2</li>
<li>Submenu 1-3</li>
</ul>
</li>
<li>Menu 2</li>
<li>Menu 3</li>
</ul>
</div>

Not able to write article after vertical menu in HTML

I am trying to write my article beside my vertical menu, but all my article going inside that menu. I want my menu to be fixed on that page on the left side and all my new articles or any pictures should come on after menu.
MY HTML
<nav id="wrapper-250">
<ul class="accordion">
<li id="one" class="files">
Health Beat
<ul class="sub-menu">
<li><em>01</em>Sub Menu 1
<ul class="sub-sub-menu">
<li><em>a</em>Sub Menu 2</li>
<li><em>b</em>Sub Menu 2</li>
<li><em>c</em>Sub Menu 2</li>
<li><em>d</em>Sub Menu 2</li>
<li><em>e</em>Sub Menu 2</li>
</ul>
</li>
<li><em>02</em>Sub Menu 1</li>
<li><em>03</em>Sub Menu 1</li>
<li><em>04</em>Sub Menu 1</li>
<li><em>05</em>Sub Menu 1</li>
</ul>
</li>
<li id="two" class="mail">
Mail
<ul class="sub-menu">
<li><em>01</em>Hotmail</li>
<li><em>02</em>Yahoo</li>
</ul>
</li>
<li id="three" class="cloud">
Cloud
<ul class="sub-menu">
<li><em>01</em>Connect</li>
<li><em>02</em>Profiles</li>
<li><em>03</em>Options</li>
<li><em>04</em>Connect</li>
<li><em>05</em>Profiles</li>
<li><em>06</em>Options</li>
</ul>
</li>
<li id="four" class="sign">
Sign Out
<ul class="sub-menu">
<li><em>01</em>Log Out</li>
<li><em>02</em>Delete Account</li>
<li><em>03</em>Freeze Account</li>
</ul>
</li>
</ul>
</nav>
<div id="body-part">
<p>
</P>
</div>
http://codepen.io/anon/pen/XbXbqQ
Add a big padding-left to your #body-part:
padding-left: 500px; /* example */
Demo here: http://jsfiddle.net/baLq1d1k/
Or you can do it using jquery if the width of your #wrapper-250 changes:
$("#body-part").css("padding-left", ($("#wrapper-250").width() + 10));

Is it possible to center the dropdown below a pill (Bootstrap)?

So now I finally got my pill dropdown working but another question then arose - as I use nav-justified to center my navbar, the pills are quite wide and the dropdown is all the way to the left of the pill. Can I center this dropdown in any way?
The JSFiddle looks like this: https://jsfiddle.net/htsda5xo/1/
A snippet of the HTML:
<div class="nav">
<ul class="nav nav-pills nav-justified">
<li class="dropdown">WEBDESIGN <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>HTML 5</li>
<li>CSS 3</li>
<li>Bootstrap 5</li>
</ul>
</li>
<li>DYNAMIC WEBDESIGN</li>
Try this,
.nav-justified>.dropdown .dropdown-menu {
/* top: auto; */
left: 50%;}
Try this
<div class="nav">
<ul class="nav nav-pills nav-justified">
<li class="dropdown">WEBDESIGN <span class="caret"></span>
<ul class="dropdown-menu text-center" role="menu">
<li>HTML 5</li>
<li>CSS 3</li>
<li>Bootstrap 5</li>
</ul>
</li>
<li>DYNAMIC WEBDESIGN</li>