I´m trying to add active style in buttons when the routes matches.
The dropdown menu elements add active style properly but parent element does not have this style.
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<li>
<a href="#" class="navbar-brand" data-toggle="dropdown" role="button" aria-expanded="false">{{'entity' |
translate}} <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li [routerLinkActive]="['active']" [routerLinkActiveOptions]="{exact:true}"><a
[routerLink]="['/entidad/listado']"><i class="fa fa-list"></i> {{'list' | translate}}</a></li>
<li [routerLinkActive]="['active']" [routerLinkActiveOptions]="{exact:true}"><a
[routerLink]="['/entidad/formulario']"><i class="fa fa-plus"></i> {{'new' | translate}}</a></li>
</ul>
</li>
<li>
</ul>
</div>
So the question is: How can i add active element in parent
{{'entity' | translate}} <span class="caret"></span>
when ul dropdown menu elements is selected?
You could try using the isActive method of the router:
https://angular.io/api/router/Router#isActive
To apply the active class to your parent <a> tag when either of the dropdown menu's routes are active, you could add a [class.active] attribute, as such:
[class.active]="router.isActive('/entidad/listado', true) || router.isActive('/entidad/formulario', true)"
So on your parent element, it would look like this:
<a href="#" class="navbar-brand" data-toggle="dropdown" role="button" aria-expanded="false"
[class.active]="router.isActive('/entidad/listado', true) || router.isActive('/entidad/formulario', true)">
{{'entity' | translate}} <span class="caret"></span>
</a>
Related
Here is the html structure:
<div class="collapse navbar-collapse main-menu-item justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav align-items-center">
<li class="nav-item"><a class="nav-link" href="/index.php"><i class="ti-home"></i></a></li>
<li class="nav-item"><a class="nav-link" href="/page2.php">Page 2</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">News</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/news/blog.php">Blog</a>
<a class="dropdown-item" href="/news/press.php">Press</a>
</div>
</li>
</ul>
</div>
I was able to display the menu through wp. But one point still needs to be fixed: the dropdown. Any idea about what I should do?
How to display the li, div and a dropdown classes through the menu?
The dropdown menu appears on the page but should be hidden until I make hover on it, doesn't it?
Should I use Jquery to do this or is it through a wp function? I am a bit lost.
Thanks for your help.
When viewing this from xs or sm viewport/screen sizes, and then clicking on my navbar toggler, it's pushing all the content, INCLUDING the header that the navbar-toggler is in, down the page to make room for the dropdown menus.
This appears to be different from Bootstrap 3 (as well as Bootstrap 4 alpha 5).
Any thoughts on how to stop doing this?
Here's the site to test...
https://test.wrestlestat.com/rankings/dual
Here's the code:
<button class="navbar-toggler d-md-none" type="button" data-toggle="collapse" data-target="#navbarSupportedContent">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
#*<li class="nav-item"><a class="nav-link" href="#WrestleStat_v3.Core.Constants.Route.ComparisonRoutes.GetDualComparisonSelectLink()">Dual Comparison</a></li>*#
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="comparisonDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Comparisons
</a>
<div class="dropdown-menu" aria-labelledby="comparisonDropdown">
<a class="dropdown-item" href="#WrestleStat_v3.Core.Constants.Route.ComparisonRoutes.GetDualComparisonSelectLink()">Dual/Team</a>
<a class="dropdown-item" href="#WrestleStat_v3.Core.Constants.Route.ComparisonRoutes.GetWrestlerComparisonSelectLink()">Wrestler</a>
#*<div class="dropdown-divider"></div>*#
<a class="dropdown-item" href="#WrestleStat_v3.Core.Constants.Route.ComparisonRoutes.GetDualComparisonSelectLink()">Perma</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="rankingsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Rankings
</a>
<div class="dropdown-menu" aria-labelledby="rankingsDropdown">
<a class="dropdown-item" href="#WrestleStat_v3.Core.Constants.Route.RankingRoutes.GetWrestlerRankingsAllLink()">Wrestler</a>
<a class="dropdown-item" href="#WrestleStat_v3.Core.Constants.Route.RankingRoutes.GetDualRankingsLink()">Dual</a>
<a class="dropdown-item" href="#WrestleStat_v3.Core.Constants.Route.RankingRoutes.GetTournamentRankingsLink()">Tournament</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="fantasyDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Comparisons
</a>
<div class="dropdown-menu" aria-labelledby="fantasyDropdown">
<a class="dropdown-item" href="#WrestleStat_v3.Core.Constants.Route.PickEmRoutes.GetFantasyThisWeekLink()">Pick'Em</a>
<a class="dropdown-item" href="#WrestleStat_v3.Core.Constants.Route.TourneyPoolRoutes.GetTourneyPoolHubLink()">Tourney Pool</a>
<a class="dropdown-item" href="#WrestleStat_v3.Core.Constants.Route.TourneyProjectionRoutes.GetTourneyProjectionLink()">Tourney Projection</a>
</div>
</li>
</ul>
</div>
Why it happens?
The class sticky-top gives your navbar a position: sticky; which acts as a block element when you haven't scrolled yet. So when your navbar gets expanded it pushes all other block elements down.
Fix1 - pushes normal content down
Put this div: <div class="navbar-collapse collapse" id="navbarSupportedContent" style>...</div> at the end of your <nav>...</nav>, or above your input if you want the searchfield to be under the collapsed navbar.
Fix2 - doesn't push anything down
First do Fix1, then in your CSS add .sticky-top { position: fixed !important; }, Only do this if your not using sticky-top anywere else!, because when you don't scroll it acts like a block element so pushes its other content down. Also add some margin to your first container-fluid so its under the header again (cause the now fixed element doesn't take up space anymore) for example add classes pt-5 and mt-5 to them.
My data-toggle="collapse" menu disappears when it is clicked.
Although it does dropdown as required, whenever a user clicks anywhere on the dropdown menu, it disappears.
What am I doing wrong ? Here is my code:
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle bg-dark " href="#" id="navbarDropdown1" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
My Account
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">Other info goes here... //before the closing div
You need to add the data-target attribute so that Bootstrap knows which one to drop down.
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle bg-dark" href="#" data-target="#navbarDropdown1" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
My Account
</a>
<div class="dropdown-menu" id="navbarDropdown1" aria-labelledby="navbarDropdown">Other info goes here... //before the closing div
my glyphicons are not working in my "dropdown" class. but it works in my "dropdown-menu" class. my first tag, the text is loaded through database, but the glyphicon is not showing up. what can I do?
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a id ="lblnames" class="dropdown-toggle" data-toggle="dropdown" runat="server" style="color:white; cursor:pointer"># <span class="glyphicon glyphicon-user"></span></a>
<ul class ="dropdown-menu">
<li>Manage Account <span class="glyphicon glyphicon-cog pull-right"></span></li>
<li><a id="endsession1" href="Account/forLogOut.aspx" style="font-family:Calibri">Log Out <span class="glyphicon glyphicon-log-out pull-right"></span></a></li>
</ul>
</li>
</ul>
I tried your code and it seems fine. The problem is that you have set the color to white in your inline CSS here:
<a id ="lblnames" class="dropdown-toggle" data-toggle="dropdown" runat="server" style="color:white; cursor:pointer"># <span class="glyphicon glyphicon-user"></span></a>
I changed the color to something else and it worked fine. :)
I am currently using the CSS bootstrap 3.2 in my application.
I am trying to place 2 drop down menu "with the arrow only- not button style" next to each other and then to the right I want to add a search bar.
I want to use the the dropdown menu that the bootstrap has but without the button style "arrow only" and a small search bar to the right in the vertical center.
I have tried to do that but the dropdown menus and the search bar do not line up.
here is a screenshot of what I have done
and here is my code
<ul class="nav nav-pills">
<li class="dropdown">
<a class="dropdown-toggle menu-sm-padding" data-toggle="dropdown" href="#">
My Name <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>My Profile</li>
<li role="presentation" class="divider"></li>
<li>Logout</li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle menu-sm-padding" data-toggle="dropdown" href="#">
My Company Name <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu"><li><a class="master_client_change" href="#" id="current_client_id_2">Comp 1</a></li><li><a class="master_client_change" href="#" id="current_client_id_1">Comp 2</a></li><li><a class="master_client_change" href="#" id="current_client_id_3">Comp 3</a></li><li><a class="master_client_change" href="#" id="current_client_id_6">Comp 4</a></li></ul>
</li>
</ul>
<div class="width-sm-size box-inline-block">
<form action="/accounts_search.php" method="get" id="searchforactivities" class="navbar-form navbar-right row-right-xxsm-margin" role="search">
<div class="input-group">
<input type="search" class="form-control" name="search_term">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">Go</button>
</span>
</div>
</form>
</div>
How can I get the dropdown menu and the search bar to line up?
and is there a trick in making the search bar little fancy by making the the corners of the input round and the Go button a search icon?