Reputation: 358
I am building a MEAN stack application. Currently, I am trying to hide certain div elements in mobile view using css media rules. And in mobile view listing it using a button dropdown which sets collapsed to true/false on click using ng-click. Its working as expected. But in mobile view, if the dropdown is activated and I expand browser to larger size, the menu comes in the web view which is not expected. Can anyone help on the same?
Below is part of the code:
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#sidbar" aria-expanded="false" aria-controls="sidbar" ng-init="sidCollapsed=true" ng-click="sidCollapsed=!sidCollapsed">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div id="sidbar" collapse="sidCollapsed" class="sidbar">
<!--<ul class="nav navbar-nav navbar-left">-->
<ul class="nav navbar-nav">
<li><a ng-class="{'active':$location.path() == '/home'}" href="#/home">Home</a></li>
<li><a ng-class="{'active':$location.path() == '/profile'}" ng-show="user" href="#/profile">Profile</a></li>
<li><a ng-class="{'active':$location.path() == '/admin'}" ng-show="user && user.roles.indexOf('admin')>=0" href="#/admin">Admin</a></li>
<li><a ng-class="{'active':$location.path() == '/forms'}" ng-show="user" href="#/forms">Forms</a></li>
</ul>
</div>
css:
@media (min-width: 768px){
.sidbar {
display:none;
}}
Upvotes: 0
Views: 257
Reputation: 20905
By the looks of things, you're using Bootstrap so you can use the hidden-xs
class
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#sidbar" aria-expanded="false" aria-controls="sidbar" ng-init="sidCollapsed=true" ng-click="sidCollapsed=!sidCollapsed">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div id="sidbar" collapse="sidCollapsed" class="sidbar hidden-xs">
<!--<ul class="nav navbar-nav navbar-left">-->
<ul class="nav navbar-nav">
<li><a ng-class="{'active':$location.path() == '/home'}" href="#/home">Home</a>
</li>
<li><a ng-class="{'active':$location.path() == '/profile'}" ng-show="user" href="#/profile">Profile</a>
</li>
<li><a ng-class="{'active':$location.path() == '/admin'}" ng-show="user && user.roles.indexOf('admin')>=0" href="#/admin">Admin</a>
</li>
<li><a ng-class="{'active':$location.path() == '/forms'}" ng-show="user" href="#/forms">Forms</a>
</li>
</ul>
</div>
You can find out more usable classes for showing and hiding elements dependent on browser size in the Bootstrap documentation.
Upvotes: 1