Bootstrap下拉菜单不显示静态菜单

时间:2015-07-01 05:29:51

标签: html css html5 twitter-bootstrap

我的网页上有一个静态菜单。其中的下拉菜单未显示。我有以下代码用于菜单。

<ul class="nav navbar-nav navbar-right collapse" id="navbar-icons">
            <li><a href="#">something</a></li>
            <li><a href="#">someting2</a></li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">dropdown<span class="caret"></span></a>
                <ul class="dropdown-menu dropdown-menu-right" id="" role="menu">
                    <li><a href="#">dropdown1</a></li>
                    <li><a href="#">dropdown2</a></li>
                    <li><a href="#">dropdown3</a></li>
                </ul>
            </li>

我无法看到下拉菜单。我的菜单工作正常,但下拉菜单不可见。但它存在于DOM上。我可以在Chrome中看到使用视图源的菜单。我能够看到小于700px的分辨率下拉菜单,即主菜单崩溃但不是其他方式。

请帮我看菜单。

7 个答案:

答案 0 :(得分:0)

确保您按照正确的顺序(在头部)给出了所有必需的CDN和CSS,如下所示:

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<div class="collapse navbar-collapse" id="myNavbar">
  <ul class="nav navbar-nav  navbar-right" id="navbar-icons">
    <li><a href="#">something</a></li>
        <li><a href="#">someting2</a></li>
        <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">dropdown<span class="caret"></span></a>
            <ul class="dropdown-menu dropdown-menu-right" id="" role="menu">
                <li><a href="#">dropdown1</a></li>
                <li><a href="#">dropdown2</a></li>
                <li><a href="#">dropdown3</a></li>
            </ul>
        </li>
     </ul>
 </div>

答案 1 :(得分:0)

<ul class="nav navbar-nav navbar-right collapse" id="navbar-icons">删除崩溃类。因为崩溃等级会隐藏下拉列表。

JSFiddle

答案 2 :(得分:0)

只需从代码

中删除崩溃即可
<ul class="nav navbar-nav navbar-right" id="navbar-icons">
    <li><a href="#">something</a></li>
    <li><a href="#">someting2</a></li>
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">dropdown<span class="caret"></span></a>
        <ul class="dropdown-menu dropdown-menu-right" id="" role="menu">
            <li><a href="#">dropdown1</a></li>
            <li><a href="#">dropdown2</a></li>
            <li><a href="#">dropdown3</a></li>
        </ul>
    </li>
</ul>

答案 3 :(得分:0)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Static Top Navbar</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/navbar-static-top.css" rel="stylesheet">
</head>

<body>

<!-- Static navbar -->
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="#">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="../navbar/">Default</a></li>
<li class="active"><a href="./">Static top</a></li>
<li><a href="../navbar-fixed-top/">Fixed top</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>

</body>
</html>

答案 4 :(得分:0)

试用这个:

JS Fiddle Link: http://jsfiddle.net/abidkhanweb/ZS4L7/1066/

答案 5 :(得分:0)

我发现了错误。我为菜单的overflow:hidden标记添加了<li>样式。这导致下拉菜单被隐藏,因为下拉被视为同一DOM元素的扩展。我为这个错误道歉,并感谢大家的快速回复。

答案 6 :(得分:-1)

collapse移除ul课程。

<ul class="nav navbar-nav navbar-right" id="navbar-icons">
...