问题
I have used span class icon bar to display that three lines symbol after resizing the windows and other components should get displayed under that icon. But when I resize the window it only shows that icon and after clicking on it nothing happens This what I have done : what's gone wrong? Thank you in advance
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<! Header -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#topNavBar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'ontheway:index' %}"> Way2go </a>
</div>
<! Items -->
<div class="collapse navbar-collapse" id="#topNavBar">
<ul class="nav navbar-nav">
<li class="active">
<a href="{% url 'ontheway:index' %}">
<span aria-hidden="true"></span> Home
</a>
</li>
<li class="">
<a href="#">
<span aria-hidden="true"></span> Hotels
</a>
</li>
<li class="">
<a href="#">
<span aria-hidden="true"></span> Homestays
</a>
</li>
</ul>
<form class="navbar-form navbar-left" role="search" method="get" action="#">
<div class="form-group">
<input type="text" class="form-control" name="q" value=""placeholder="Search tourist places,hotels, homestays here">
</div>
<button type="submit" class="btn btn-default"> Search</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li class="">
<a href="#">
<span class="glyphicon glyphicon-bell" aria-hidden="true"></span> Notifications
</a>
<li class="">
<a href="#">
<span aria-hidden="true"></span> Log in
</a>
</li>
<li class="">
<a href="#">
<span aria-hidden="true"></span> Sign up
</a>
</li>
</ul>
</div>
</div>
</nav>
回答1:
@pratik jaiswal, your issue stems from the value of the id
attribute on your element with the collapse
class.
<!-- Header ---->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#topNavBar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'ontheway:index' %}"> Way2go </a>
</div>
<!-- Items ---->
<div class="collapse navbar-collapse" id="#topNavBar"> <!--Take out the hash symbol-->
...
You have it with a leading #
. If you take that out, your issue will be resolved.
You can see it in action in this codeply.
来源:https://stackoverflow.com/questions/46122964/bootstapspan-class-icon-bar-not-working