如何使下拉链接的头部可以在导航栏中单击

时间:2017-05-18 08:47:38

标签: javascript html css twitter-bootstrap-3

我希望在父链接悬停时显示dropdown个项目,并且可以点击到另一个页面,这怎么办?



<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-nav" 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 navbar-link" href="#"> <img src="assets/img/Saydullogo.png" id="logo"></a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="app-nav">
      <ul class="nav navbar-nav navbar-right">
          <li class="active"><a href="index.php"><span class="fa fa-home"></span> Home</a></li>
          <li class="dropdown">
          <a href="Categories.php" class="dropdown-toggle" data-toggle="dropdown"><span class="fa fa-medkit"></span> Categories <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Beauty</a></li>
            <li><a href="#">Cosmetics</a></li>
            <li><a href="#">Medicines</a></li>
          </ul>
        </li>
          <li><a href="#"><span class="fa fa-edit"></span> Registeration</a></li>
          <li><a href="#"><span class="fa fa-phone-square"></span> Contact Us</a></li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:4)

将此css放入您的代码中

.dropdown:hover .dropdown-menu {
   display: block !important;
}

使用您的代码查看此代码段

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

<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-nav" 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 navbar-link" href="#"> <img src="assets/img/Saydullogo.png" id="logo"></a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="app-nav">
      <ul class="nav navbar-nav navbar-right">
          <li class="active"><a href="index.php"><span class="fa fa-home"></span> Home</a></li>
          <li class="dropdown">
          <a href="Categories.php" class="dropdown-toggle" ><span class="fa fa-medkit"></span> Categories <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Beauty</a></li>
            <li><a href="#">Cosmetics</a></li>
            <li><a href="#">Medicines</a></li>
          </ul>
        </li>
          <li><a href="#"><span class="fa fa-edit"></span> Registeration</a></li>
          <li><a href="#"><span class="fa fa-phone-square"></span> Contact Us</a></li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

答案 1 :(得分:0)

this.girish-该代码完美运行。