Gibt es eine Möglichkeit, ein horizontales Untermenü für eine vertikale Menüstruktur mit Bootstrap zu erstellen Ich habe keine Untermenüs mit vertikaler Ausrichtung des Hauptmenüs gesehen. Eine Beispielstruktur der Menüstruktur ähnelt dieser Horizontales Untermenü für ein vertikales Hauptmenü mit Bootstrap
2
A
Antwort
1
Hier können here
HTML gefunden werden!
Dropdown-Menüs arbeiten mit verschachtelten „ul“, absoluten Positionen, und wir werden display: none;
-display:block;
, wenn sie mit Hover Bedarf ändern.
Etwas wie folgt aus:
<ul>
<li><a href="#">…</a>
<ul>
<li><a href="#">…</a>
<ul> … <!-- And so on. -->
</ul>
</li>
<li>
</ul>
Ihr Beispiel HTML
<nav id="main-nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Projects</a>
<ul>
<li><a href="#">Project 1</a>
<ul>
<li><a href="#">Project 2</a>
<ul>
<li><a href="#">Project 3</a>
<ul>
<li><a href="#">Project 4</a>
<ul>
<li><a href="#">Project 5</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
Ihre explame des SCSS: (Ich habe sass, weil es einfacher ist, zu lesen und zu schreiben, aber ich werde auch unten ein CSS)
#main-nav{
ul{ /* Those lines are used only for styling */
margin: 0;
padding: 0;
border-right: 1px solid black;
width: 150px;
list-style-type: none;
li{
position: relative; /* This is important when using absolute positions. */
&:hover{
&:before{ /* arrow styles */
content: "";
top: 0;
bottom: 0;
right: 0;
border-top: 5px solid transparent;
border-right: 5px solid #999;
border-bottom: 5px solid transparent;
border-left: 5px solid transparent;
position: absolute;
height: 0px;
width: 0px;
margin: auto;
}
> ul{
display: block; /* IMPORTANT: This will show your dropdown menus when hover in the parent li. */
/*&:before { // I don't like this part but if you enable it, it will make child ul's look closer to your design.
content: "";
position: absolute;
right: 0;
top: -65px;
bottom: -35px;
width: 1px;
background-color: #ccc;
}*/
}
}//:hover
a{ /* Those lines are used only for styling */
padding: 7px 10px;
display: block;
&:hover{
color: red;
}
}// a
> ul{ /* This is what makes the magic happen. */
display: none; /* Dropdown menus are always hidden, except when you hover it's li parent */
position: absolute; /* This will position the ul */
top: 0;
left: 100%; /* This will push the ul where it is needed. */
border-right: 1px solid #ccc;
}
}// li
}// ul
}
Ein Live-Beispiel: https://jsfiddle.net/xwazzo/3spxxk1z/
Und die versprochene CSS Version:
#main-nav ul {
margin: 0;
padding: 0;
border-right: 1px solid black;
width: 150px;
list-style-type: none;
}
#main-nav ul li { position: relative; }
#main-nav ul li:hover:before {
content: "";
top: 0;
bottom: 0;
right: 0;
border-top: 5px solid transparent;
border-right: 5px solid #999;
border-bottom: 5px solid transparent;
border-left: 5px solid transparent;
position: absolute;
height: 0px;
width: 0px;
margin: auto;
}
#main-nav ul li:hover > ul { display: block; }
#main-nav ul li a {
padding: 7px 10px;
display: block;
}
#main-nav ul li a:hover { color: red; }
#main-nav ul li > ul {
display: none;
position: absolute;
top: 0;
left: 100%;
border-right: 1px solid #ccc;
}
1
Dies könnte für Sie hilfreich sein.
<div class="container-fluid">
<ul class="nav nav-justified navbar-default">
<li class="dropdown">
<a href="#" data-toggle="collapse" data-target="#one">One</a>
</li>
<li class="dropdown">
<a href="#" data-toggle="collapse" data-target="#two">Two</a>
</li>
<li class="dropdown">
<a href="#" data-toggle="collapse" data-target="#three">Three</a>
</li>
<li class="dropdown">
<a href="#" data-toggle="collapse" data-target="#four">Four</a>
</li>
<li class="dropdown">
<a href="#" data-toggle="collapse" data-target="#five">Five</a>
</li>
</ul>
</div>
<div class="container-fluid">
<nav id="submenu">
<ul class="nav nav-justified">
<li>
<ul class="nav nav-justified collapse" id="one">
<li><a href="#" id="">One sub 1</a></li>
<li><a href="#" id="">One sub 2</a></li>
<li><a href="#" id="">One sub 3</a></li>
<li><a href="#" id="">One sub 4</a></li>
</ul>
</li>
<li>
<ul class="nav nav-justified collapse" id="two">
<li><a href="#" id="">Two sub 1</a></li>
<li><a href="#" id="">Two sub 2</a></li>
<li><a href="#" id="">Two sub 3</a></li>
</ul>
</li>
<li>
<ul class="nav nav-justified collapse" id="three">
<li><a href="#" id="">Three sub 1</a></li>
<li><a href="#" id="">Three sub 2</a></li>
</ul>
</li>
<li>
<ul class="nav nav-justified collapse" id="four">
<li><a href="#" id="">Four sub 1</a></li>
<li><a href="#" id="">Four sub 2</a></li>
</ul>
</li>
<li>
<ul class="nav nav-justified collapse" id="five">
<li><a href="#" id="">Link</a></li>
<li><a href="#" id="">Link</a></li>
</ul>
</li>
</ul>
</nav>
</div>
CSS:
.navbar {
margin-bottom:-1px;
border-radius:0;
}
#submenu {
background-color: none;
margin-bottom:10px;
padding-bottom:15px;
margin-top:-20px
margin-left:10px;
margin-right:10px;
display:none;
}
.collapsing {
display:none;
}
#submenu.navbar {
background-color:transparent;
border:0;
}
JS: Wir gehen
$('.collapse').on('shown.bs.collapse', function (e) {
$('.collapse').not(this).removeClass('in');
});
$('[data-toggle=collapse]').click(function (e) {
$('[data-toggle=collapse]').parent('li').removeClass('active');
$(this).parent('li').toggleClass('active');
$("#submenu").show();
});
Verwandte Themen
- 1. Horizontales Untermenü
- 2. bootstrap 3 Hide das Hauptmenü, wenn Element mit Untermenü ist klicken und Untermenü anzeigen
- 3. ASP.NET horizontales Menü mit darunter erscheinendem Untermenü, auch horizontal
- 4. Vertikales Dropdown mit horizontalem Untermenü allignment
- 5. qgraphicsview horizontales Scrollen hat immer ein vertikales Delta
- 6. iPhone - Nesting UIScrollViews für horizontales Paging und vertikales Scrollen
- 7. Bidirektionaler Touch Swipe-Schieberegler für horizontales und vertikales
- 8. UICollectionView - vertikales Scrollen, horizontales Paging mit benutzerdefiniertem Layout
- 9. Android-Untermenü: Zurück zum vorherigen Untermenü (oder zum Hauptmenü vom Untermenü)
- 10. Bootstrap horizontales Menü mit der Maus über horizontale Untermenü mit gab
- 11. Twitter Bootstrap Horizontales Formular
- 12. Bootstrap Horizontales Multilevel-Menü
- 13. Trennlinie für vertikales LinearLayout?
- 14. Hauptmenü Bootstrap zentriert (SmartAdmin Template)
- 15. Bootstrap 3 vertikales Menü mit umschaltbaren Untermenüs
- 16. So implementieren Sie horizontales und vertikales Smooth Scrolling
- 17. Horizontales und vertikales Scrollen in der Android-Recycler-Ansicht
- 18. Horizontales Scrollen wie vertikales Scrollen in IntelliJ IDEA
- 19. Zurück zum Hauptmenü aus dem Untermenü in Java
- 20. Bootstrap angulsrjs mit Untermenü-Link funktioniert nicht
- 21. WPF vertikales Menü - zeigt das erste Untermenü links
- 22. Horizontales Histogramm in OpenCV
- 23. Horizontales Scrollen für UITableView
- 24. Untermenü Bootstrap .active state funktioniert nicht richtig
- 25. Medienabfrage für vertikales Scrollen
- 26. Horizontales Scrollen in UICollectionView deaktivieren
- 27. Vertikales Menü mit versteckten Untermenüs
- 28. CSS-Menü Untermenü Probleme
- 29. Untermenü mit angular2
- 30. Untermenü mit Anpassungsbreite
super, Danke für das Live-Beispiel, wie kann ich mehr Untermenü als Inline für das Hauptmenü Projekt hinzufügen, denn wenn ich Untermenü hinzufügen für sein Projekt als vertikale Struktur kam . –
Ich verstehe nicht, was Sie meinen, aber vielleicht möchten Sie etwas wie Projekt 1.1, Projekt 1.2, etc. hinzufügen? Live-Beispiel: https://jsfiddle.net/xwazzo/3spxxk1z/1/ – xWaZzo