gpt4 book ai didi

CSS Bootstrap 多级导航

转载 作者:太空宇宙 更新时间:2023-11-04 07:49:59 25 4
gpt4 key购买 nike

我正在尝试使用 Bootstrap 进行多级导航。现在我有这样的导航。

.navbar-custom {
background: #42596b !important;
border: 1px solid #42596b;
}

.navbar-custom .navbar-brand {
color: #ffffff;
}

.navbar-custom .navbar-brand:hover {
color: #cecece;
}

.navbar-custom .navbar-nav li a {
color: #ffffff;
}

.navbar-custom .navbar-nav .dropdown a {
background: #3e3f49;
}

.navbar-custom .navbar-nav .dropdown-menu li a {
color: #00a3b5;
}

.navbar-default .navbar-nav>li>a:hover,
.navbar-default .navbar-nav>li>a:focus {
color: #ade3ff;
}

.navbar-custom .multi-level {
background: #3e3f49;
padding: 24px 0;
letter-spacing: 2px;
}

.navbar-custom .navbar-nav .multi-level .dropdown-submenu {
border-top: 1px solid transparent;
border-bottom: 1px solid transparent;
padding: 10px 21px;
}

.navbar-custom .navbar-nav .multi-level .dropdown-submenu:hover {
border-top: 1px solid #35363f;
border-bottom: 1px solid #35363f;
padding: 10px 21px;
}

.navbar-custom .navbar-nav .multi-level .dropdown-submenu>a {
text-decoration: none;
position: relative;
color: #fff !important;
line-height: 24px;
font-size: 14px;
padding: 0;
text-transform: none;
line-height: 1.2;
}

.navbar-brand {
padding-top: 6px;
}

.navbar-brand img {
width: 52px;
display: inline-block;
}

.navbar-brand span {
display: inline-block;
}


/* Dropdown submenu */

.dropdown-submenu {
position: relative;
}

.dropdown-submenu>.dropdown-menu {
top: 59px;
left: 100%;
position: absolute;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
padding: 24px 0;
min-width: 490px;
height: 410px;
}

.dropdown-submenu>.dropdown-menu ul {
float: left;
width: 50%;
padding: 0 10px 0 21px;
list-style: none;
margin: 0px;
}

.dropdown-submenu>.dropdown-menu ul>.category-label,
.dropdown-submenu>.dropdown-menu ul>.feature-label {
font-size: 14px;
font-weight: 600;
padding-left: 0px;
margin-bottom: 10px;
padding: 11px 0 7px;
line-height: 1.2;
color: #3e3f49;
}

.dropdown-submenu>.dropdown-menu>.feature-list>li {
border-left: 1px solid #dbdbdb;
}

.dropdown-submenu>.dropdown-menu ul>.feature-label {
color: #ad452d;
border: none;
}

.dropdown-submenu>.dropdown-menu ul>.level1 {
padding-left: 12px;
padding-bottom: 19px;
}

.dropdown-submenu>.dropdown-menu li a {
background: #ffffff !important;
text-transform: none;
color: #3e3f49 !important;
font-weight: normal;
}

.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<nav class="navbar navbar-default navbar-fixed-top navbar-custom">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img src="img/logo.png">
<span>Brand</span>
</a>
</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
<a id="dLabel" role="button" data-toggle="dropdown" class="btn btn-primary" data-target="#" href="/page.html">
MENU <span class="caret"></span>
</a>
<ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Informacije</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Najave Dogadjaja</li>
<li class="level1"><a href="#">Seminari</a></li>
<li class="level1"><a href="#">Savetovanja</a></li>
<li class="level1"><a href="#">Predavanja</a></li>
<li class="level1"><a href="#">Radionice</a></li>
<li class="level1"><a href="#">Manifestacije</a></li>
<li class="level1"><a href="#">Posete</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Strucni Saveti</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Strucni Saveta</li>
<li class="level1"><a href="#">Forum - Potrazite Strucni Savet</a></li>
<li class="level1"><a href="#">Preporuke</a></li>
<li class="level1"><a href="#">SMSZnanje</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Savetodavstvo</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Savetodavstvo</li>
<li class="level1"><a href="#">Pokrajinski Sekretarijat</a></li>
<li class="level1"><a href="#">Centar Za Usavrsavanje</a></li>
<li class="level1"><a href="#">Centar Za Ruralni Razvoj</a></li>
<li class="level1"><a href="#">Savetodavne Sluzbe</a></li>
<li class="level1"><a href="#">Savetodavci</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Publikacije</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Publikacije</li>
<li class="level1"><a href="#">Prezentacije</a></li>
<li class="level1"><a href="#">Aktuelni Savetnik</a></li>
<li class="level1"><a href="#">Rezultati Ogleda</a></li>
<li class="level1"><a href="#">Bilteni PSS</a></li>
<li class="level1"><a href="#">Agroplaner</a></li>
<li class="level1"><a href="#">Ostala Dokumenta</a></li>
<li class="level1"><a href="#">Uputsva i Prirucnici</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Pravilnici, Konkursi, Uredbe</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Pravilnici, Konkursi, Uredbe</li>
<li class="level1"><a href="#">Pravilnici, Konkursi, Uredbe</a></li>
<li class="level1"><a href="#">Konkursi APV</a></li>
<li class="level1"><a href="#">Ostali Konkursi</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Ostali Prilozi</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Ostali Prilozi</li>
<li class="level1"><a href="#">Korisni Linkovi</a></li>
<li class="level1"><a href="#">Korisni Alati</a></li>
<li class="level1"><a href="#">Prikaz Aktuelnih Izdanja</a></li>
<li class="level1"><a href="#">Doktorske Disertacije</a></li>
<li class="level1"><a href="#">Pisma Administratoru</a></li>
<li class="level1"><a href="#">Objavljeno na Medijima</a></li>
<li class="level1"><a href="#">Uslovi Koriscenja</a></li>
<li class="level1"><a href="#">In Memoriam</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Galerija</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Galerija</li>
<li class="level1"><a href="#">Video Zapisi</a></li>
<li class="level1"><a href="#">Fotografije</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>

JSFiddle

如何使我的子菜单(白色的)始终与主菜单(黑色的)保持在同一行的顶部

最佳答案

只需将 top 的值替换为 .dropdown-submenu>.dropdown-menu 并设为 0 即可:

.dropdown-submenu>.dropdown-menu {
top: 0;
...

}

并从 .dropdown-submenu 中移除相对位置

完整代码:

.navbar-custom {
background: #42596b !important;
border: 1px solid #42596b;
}

.navbar-custom .navbar-brand {
color: #ffffff;
}

.navbar-custom .navbar-brand:hover {
color: #cecece;
}

.navbar-custom .navbar-nav li a {
color: #ffffff;
}

.navbar-custom .navbar-nav .dropdown a {
background: #3e3f49;
}

.navbar-custom .navbar-nav .dropdown-menu li a {
color: #00a3b5;
}

.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus {
color: #ade3ff;
}

.navbar-custom .multi-level {
background: #3e3f49;
padding: 24px 0;
letter-spacing: 2px;
}

.navbar-custom .navbar-nav .multi-level .dropdown-submenu {
border-top: 1px solid transparent;
border-bottom: 1px solid transparent;
padding: 10px 21px;
}

.navbar-custom .navbar-nav .multi-level .dropdown-submenu:hover {
border-top: 1px solid #35363f;
border-bottom: 1px solid #35363f;
padding: 10px 21px;
}

.navbar-custom .navbar-nav .multi-level .dropdown-submenu>a {
text-decoration: none;
position: relative;
color: #fff !important;
line-height: 24px;
font-size: 14px;
padding: 0;
text-transform: none;
line-height: 1.2;
}

.navbar-brand {
padding-top: 6px;
}

.navbar-brand img {
width: 52px;
display: inline-block;
}

.navbar-brand span {
display: inline-block;
}
/* Dropdown submenu */


.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
position: absolute;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
padding: 24px 0;
min-width: 490px;
height: 410px;
}

.dropdown-submenu>.dropdown-menu ul {
float: left;
width: 50%;
padding: 0 10px 0 21px;
list-style: none;
margin: 0px;
}

.dropdown-submenu>.dropdown-menu ul>.category-label, .dropdown-submenu>.dropdown-menu ul>.feature-label {
font-size: 14px;
font-weight: 600;
padding-left: 0px;
margin-bottom: 10px;
padding: 11px 0 7px;
line-height: 1.2;
color: #3e3f49;
}

.dropdown-submenu>.dropdown-menu>.feature-list>li {
border-left: 1px solid #dbdbdb;
}

.dropdown-submenu>.dropdown-menu ul>.feature-label {
color: #ad452d;
border: none;
}

.dropdown-submenu>.dropdown-menu ul>.level1 {
padding-left: 12px;
padding-bottom: 19px;
}

.dropdown-submenu>.dropdown-menu li a {
background: #ffffff !important;
text-transform: none;
color: #3e3f49 !important;
font-weight: normal;
}

.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<nav class="navbar navbar-default navbar-fixed-top navbar-custom">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img src="img/logo.png" >
<span>Brand</span>
</a>
</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
<a id="dLabel" role="button" data-toggle="dropdown" class="btn btn-primary" data-target="#" href="/page.html">
MENU <span class="caret"></span>
</a>
<ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Informacije</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Najave Dogadjaja</li>
<li class="level1"><a href="#">Seminari</a></li>
<li class="level1"><a href="#">Savetovanja</a></li>
<li class="level1"><a href="#">Predavanja</a></li>
<li class="level1"><a href="#">Radionice</a></li>
<li class="level1"><a href="#">Manifestacije</a></li>
<li class="level1"><a href="#">Posete</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Strucni Saveti</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Strucni Saveta</li>
<li class="level1"><a href="#">Forum - Potrazite Strucni Savet</a></li>
<li class="level1"><a href="#">Preporuke</a></li>
<li class="level1"><a href="#">SMSZnanje</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Savetodavstvo</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Savetodavstvo</li>
<li class="level1"><a href="#">Pokrajinski Sekretarijat</a></li>
<li class="level1"><a href="#">Centar Za Usavrsavanje</a></li>
<li class="level1"><a href="#">Centar Za Ruralni Razvoj</a></li>
<li class="level1"><a href="#">Savetodavne Sluzbe</a></li>
<li class="level1"><a href="#">Savetodavci</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Publikacije</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Publikacije</li>
<li class="level1"><a href="#">Prezentacije</a></li>
<li class="level1"><a href="#">Aktuelni Savetnik</a></li>
<li class="level1"><a href="#">Rezultati Ogleda</a></li>
<li class="level1"><a href="#">Bilteni PSS</a></li>
<li class="level1"><a href="#">Agroplaner</a></li>
<li class="level1"><a href="#">Ostala Dokumenta</a></li>
<li class="level1"><a href="#">Uputsva i Prirucnici</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Pravilnici, Konkursi, Uredbe</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Pravilnici, Konkursi, Uredbe</li>
<li class="level1"><a href="#">Pravilnici, Konkursi, Uredbe</a></li>
<li class="level1"><a href="#">Konkursi APV</a></li>
<li class="level1"><a href="#">Ostali Konkursi</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Ostali Prilozi</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Ostali Prilozi</li>
<li class="level1"><a href="#">Korisni Linkovi</a></li>
<li class="level1"><a href="#">Korisni Alati</a></li>
<li class="level1"><a href="#">Prikaz Aktuelnih Izdanja</a></li>
<li class="level1"><a href="#">Doktorske Disertacije</a></li>
<li class="level1"><a href="#">Pisma Administratoru</a></li>
<li class="level1"><a href="#">Objavljeno na Medijima</a></li>
<li class="level1"><a href="#">Uslovi Koriscenja</a></li>
<li class="level1"><a href="#">In Memoriam</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Galerija</a>
<nav class="dropdown-menu">
<ul class="level0">
<li class="category-label">Galerija</li>
<li class="level1"><a href="#">Video Zapisi</a></li>
<li class="level1"><a href="#">Fotografije</a></li>
</ul>

<ul class="feature-list level0">
<li class="feature-label">Feature title</li>
<li class="level1"><a href="#">Second level</a></li>
<li class="level1"><a href="#">Second level</a></li>
</ul>
</nav>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>

关于CSS Bootstrap 多级导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47855248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com