我正在建立一个网站,我需要拥有15个HTML文件。我使用3个直接链接navbar
和2个下拉菜单制作了nav-items
。
如何使下拉菜单在点击时不显示但在鼠标悬停时显示,并在单击时将我发送到下拉href
链接?
我试图将nav-item
类和dropdown-menu
类放在一起,但是它不起作用。
有我的导航栏:
<nav class="navbar navbar-expand-lg navbar-light bg-white">
<div class="container">
<a class="navbar-brand" href="index.html"><img src="img/logotxt.png" width="150"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto text-uppercase font-weight-bold small">
<li class="nav-item mr-3 pr-3 border-right active">
<a class="nav-link p-0 text-blue" href="index.html">Domov</a>
</li>
<li class="nav-item mr-3 pr-3 border-right dropdown">
<a class="nav-link p-0 text-blue dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
O klubu
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item small" href="#">Dosežki</a>
<a class="dropdown-item small" href="#">Zgodovina</a>
<a class="dropdown-item small" href="#">Zanimivosti</a>
</div>
</li>
<li class="nav-item mr-3 pr-3 border-right text-blue">
<a class="nav-link p-0 text-blue" href="#">Prva ekipa</a>
</li>
<li class="nav-item mr-3 pr-3 border-right dropdown">
<a class="nav-link p-0 text-blue dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Rezultati
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item small" href="#">Španska liga</a>
<a class="dropdown-item small" href="#">Španski pokal</a>
<a class="dropdown-item small" href="#">Liga prvakov</a>
</div>
</li>
<li class="nav-item text-blue">
<a class="nav-link p-0 text-blue" href="#">Kontakt</a>
</li>
</ul>
</div>
</div>
</nav>
答案 0 :(得分:1)
如果您想悬停
简单仅CSS解决方案:
.dropdown:hover>.dropdown-menu {
display: block;
}
您可以编辑或预览Here On JSFiddle
和
href
属性指定链接的目的地:
<a href="https://www.w3schools.com">Visit W3Schools</a> <!-- Example -->
如果您想单击任何页面(假设您想单击“关于”页面),则只需像这样使用
<a href="About.html">About</a>