My Navbar:
Problem
How can I get the admin menu item to be in the middle rather than dropping to the left? I'm using a template I purchased from wrapbootstrap and cannot figure out why this is happening. I've tweaked a lot of CSS using the dev tools in firefox and no matter what I do, ADMIN hangs to the left.
CSS:
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active">#Html.ActionLink("Home", "Index", "Home", new { area = "" }, new { })</li>
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">Games</a>
<ul role="menu" class="dropdown-menu">
<li>#Html.ActionLink("Results", "Index", "Results", new { area = "" }, new { })</li>
<li>#Html.ActionLink("League Table", "Index", "LeagueTable", new { area = "" }, new { })</li>
</ul>
</li>
<li>#Html.ActionLink("Schedule", "Index", "Schedule", new { area = "" }, new { })</li>
<li>#Html.ActionLink("Players", "Index", "Players", new { area = "" }, new { })</li>
<li>#Html.ActionLink("News", "Index", "News", new { area = "" }, new { })</li>
<li>#Html.ActionLink("Gallery", "Index", "Gallery", new { area = "" }, new { })</li>
<li>#Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { })</li>
#if (Request.IsAuthenticated)
{
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">Admin</a>
<ul role="menu" class="dropdown-menu">
<li>#Html.ActionLink("Admin Home", "Index", "Home", new { area = "Admin" }, new { })</li>
<li>#Html.ActionLink("Games", "Index", "Games", new { area = "Admin" }, new { })</li>
<li>#Html.ActionLink("Game Types", "Index", "GameTypes", new { area = "Admin" }, new { })</li>
<li>#Html.ActionLink("News", "Index", "News", new { area = "Admin" }, new { })</li>
<li>#Html.ActionLink("Players", "Index", "Players", new { area = "Admin" }, new { })</li>
<li>#Html.ActionLink("Seasons", "Index", "Seasons", new { area = "Admin" }, new { })</li>
</ul>
</li>
}
</ul>
</div>
</div>
</nav>
I had a similar problem before. I reduced the font-size.
.nav.navbar-nav.navbar-right li a {
/*reduce font-size here*/
}
I reduced the padding between the navbar elements.
.navbar-nav > li{
padding-left:30px;/*reduce*/
padding-right:30px;
}
You can also change the margins. It works too:
.navbar-nav > li{
margin-left:30px;
margin-right:30px;
}
Another way to go about it is using the media queries: check which screen-size has the admin dropping down and maybe turn one or two elements into a dropdown at that screen-size: for example have gallery and contacts into a dropdown called More. So when the user clicks it, he will have the option to choose between the two.
Related
I am making menu with categories, where first menu item is All categories. All items call method Index in controller Auction, however, first item does not send id as a parameter. I am curious, why I can not call method from view without asp-route-id and I have to set asp-route-id to null for the first item? Otherwise, it will set id the id of last clicked menu item. Are there another way how to solve the issue?
Works:
<div class="menu">
#if (Model.CurrentCategory == null)
{
<a class="d-block active" asp-controller="Auction" asp-action="Index" asp-route-id=null><span></span>All categories</a>
}
else
{
<a class="d-block" asp-controller="Auction" asp-action="Index" asp-route-id=null><span></span>All categories</a>
}
#foreach (var category in Model.Categories)
{
#if (#category.Id_category == Model.CurrentCategory)
{
<a class="d-block active" asp-controller="Auction" asp-action="Index" asp-route-id="#category.Id_category"><span></span>#category.Name</a>
}
else
{
<a class="d-block" asp-controller="Auction" asp-action="Index" asp-route-id="#category.Id_category"><span></span>#category.Name</a>
}
}
</div>
Does not work (copy id from last clicked menu item):
<div class="menu">
#if (Model.CurrentCategory == null)
{
<a class="d-block active" asp-controller="Auction" asp-action="Index"><span></span>All categories</a>
}
else
{
<a class="d-block" asp-controller="Auction" asp-action="Index" ><span></span>All categories</a>
}
#foreach (var category in Model.Categories)
{
#if (#category.Id_category == Model.CurrentCategory)
{
<a class="d-block active" asp-controller="Auction" asp-action="Index" asp-route-id="#category.Id_category"><span></span>#category.Name</a>
}
else
{
<a class="d-block" asp-controller="Auction" asp-action="Index" asp-route-id="#category.Id_category"><span></span>#category.Name</a>
}
}
</div>
ASPNet MVC add Id at the end of your route becuase it is set as default URL Route pattern, passing the Id is optional. It is set up when you create the application. Have a look in StartUp.cs
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
or Program.cs in ASPNet Core
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
HTML code
<div class="card-header">
<h5>Refill by date</h5>
<div class="card-header-right">
<nav class="navbar bg-faded ">
<ul class="nav navbar-nav">
<li class="nav-item" routerLinkActive="active">
<button (click)="setView('branch'); getFranchiseRefillsByDateAndBranch()" class="btn btn-mini btn-bg-c-blue btn-outline-default btn-round btn-action">
<i class="icofont icofont-ui-check"> By branch</i>
</button>
</li>
<li class="nav-item" routerLinkActive="active">
<button (click)="setView('product'); getFranchiseRefillsByDateAndProduct()" class="btn btn-mini btn-bg-c-blue btn-outline-default btn-round btn-action">
<i class="icofont icofont-ui-check"> By product</i>
</button>
</li>
<li class="nav-item" routerLinkActive="active">
<button (click)="setView('list'); getFranchiseRefillsByDateAndList()" class="btn btn-mini btn-bg-c-blue btn-outline-default btn-round btn-action">
<i class="icofont icofont-ui-check"> Refill list</i>
</button>
</li>
</ul>
</nav>
</div>
</div>
part of TS code
getFranchiseRefillsByDateAndBranch() {
this.items = [];
var hrchyIds = this.jwtHelperService.getFRefillHrchyIds();
var ym = this.localStorage.retrieve('frym');
if (hrchyIds) {
this.refillService.getFranchiseRefillsByDateAndYear(hrchyIds, ym, "branch", this.page, this.rec).subscribe(val => {
this.items = val;
});
}
}
CSS code
.nav-item.active button i{
color: #3D94CD !important;
}
I am trying to change color of active button using router link active but this method does not work in this case, is their any alternate way of adding class dynamically, based on current click.
routerLinkActive works if there was a routerLink on this element.
Keep currentActiveItem variable in ts file. Set some default value say "branch"
currentActiveItem : string = "branch"
Change value of this variable in setView function.
And additionally also use ngClass as following on correspondiong li elements.
[ngClass]="{'active' : currentActiveItem == 'branch'}"
[ngClass]="{'active' : currentActiveItem == 'product'}"
[ngClass]="{'active' : currentActiveItem == 'list'}"
I have the following code in my React render function:
<div ref="btnGroup" className="dropdown">
<button class="dropdown-toggle" data-toggle="toggle" onClick={this.toggleDropdown}></button>
<ul class="scrollable-menu-parent dropdown-menu">
<div>
<form class="droplist-panel">
<input class="droplist-search" />
<div class="scrollable-menu">
<li class="dropdown-item"> </li>
...
...
</div>
</form>
</div>
</ul>
</div>
In the toggle dropdown function, I am adding the open class to the topmost div.
However, the <ul> is not getting the auto dropdown style when it is open, the width is way larger and the positioning is also incorrect.
Am I doing something wrong here with the dropdown, dropdown-toggle and dropdown-menu which is causing the <ul> to not get correct classes?
Edit:
toggleDropdown() {
const $el = $(this.refs.btnGroup);
if ($el.is('.open')) {
this.closeDropdown($el);
}
else {
this.openDropdown($el);
}
},
closeDropdown(ele) {
ele.removeClass('open');
this.clearState();
},
openDropdown(ele) {
ele.addClass('open');
if (this.props.onOpen) {
this.props.onOpen.bind(this)();
}
},
I have a left sidebar menu which is populated by <li> and <ul> tag elements. I have handled the menu click event to expand/collapse the sub-menu items.
The problem I am facing here is I am not able to pass/identify the current instance of the tag element to do the expand/collapse i.e. If i expand a particular menu item all the other menus items are also getting affected. How do i handle this issue by identifying the current instance to do the required changes.
Please refer the snapshot about the issue
my HTML looks like below
<li [class.active]="menuLinkActive" (click)="MenuLinkToggle($event)">
<a><i class="fa fa-home"></i> Home <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu" [style.display]="subMenuDisplay">
<li>
Dashboard
</li>
<li>
Dashboard2
</li>
<li>
Dashboard3
</li>
</ul>
</li>
<li [class.active]="menuLinkActive" (click)="MenuLinkToggle($event)">
<a><i class="fa fa-edit"></i> Forms <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu" [style.display]="subMenuDisplay">
<li>
General Form
</li>
<li>
Advanced Components
</li>
</ul>
</li>
my component where i have handled the events
export class Layout {
menuLinkActive: any;
subMenuDisplay: any;
isSubMenuExpanded: any;
isMenuVisible: any;
MenuLinkToggle(event) {
if (this.isSubMenuExpanded) {
console.log("if (this.isMenuExpanded) {");
this.menuLinkActive = "";
this.subMenuDisplay = "none";
this.isSubMenuExpanded = false;
}
else {
console.log("else (this.isMenuExpanded) {");
this.menuLinkActive = "active";
this.subMenuDisplay = "block";
this.isSubMenuExpanded = true;
}
}
}
<li [class.active]="menuLinkActive" #li1 (click)="MenuLinkToggle($event, li1)">
MenuLinkToggle(event, element) {
or
MenuLinkToggle(event) {
event.target...
After changing my theme rrom default ASP.net MVC theme to BootStrap I got some styling issue in NavBar, Log off should be in same line with Hello, admin:
This's my _NavBar.cshtml :
#helper ActiveItem(string actionName, string controllerName, string areaName)
{
if (ViewContext.RouteData.Values["action"].ToString() == actionName &&
ViewContext.RouteData.Values["controller"].ToString() == controllerName &&
(ViewContext.RouteData.DataTokens["area"] == null || ViewContext.RouteData.DataTokens["area"].ToString() == areaName))
{
#:active
}
}
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Navbar header and form mobile version -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<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="#">PFE</a>
</div>
<!-- Menu Link list and Deconnexion button -->
<div class="navbar-collapse collapse">
<p class="navbar-text navbar-right">
#Html.Partial("_LoginPartial")
</p>
<ul class="nav navbar-nav">
<li class="#ActiveItem("Index", "Home", null)">#Html.ActionLink("Home", "Index", "Home")</li>
<li class="#ActiveItem("About", "Home", null)">#Html.ActionLink("About", "About", "Home")</li>
<li class="#ActiveItem("Contact", "Home", null)">#Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
</div>
</div>
And this _LoginPartial.cshtml :
#if (Request.IsAuthenticated) {
<text>
Hello, #Html.ActionLink(User.Identity.Name, "Manage", "Account", routeValues: null, htmlAttributes: new { #class = "username", title = "Manage" })!
#using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" })) {
#Html.AntiForgeryToken()
Log off
}
</text>
}
else {
<text>
#Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })
| #Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })
</text>
}
Html code After interpted by Chrome:
Hello, <a class="username" href="/Account/Manage" title="Manage">admin</a>!
<form action="/Account/LogOff" id="logoutForm" method="post"><input name="__RequestVerificationToken" type="hidden" value="FouTIIlrUNMPSCuPnaUtLA-zm5Q5ya2-24OFPZF5EWKECyyN7l4F1SOIClnfUU_2CzEbq6tQSAJ_EDKbLJLA6Hzc4Gc_OSTWbHfXmSdwV8E1" />
Log off
</form>
How to fix it please?
Your form is probably being treated as a block. Just use display: inline-block property on it and it should be fixed.
#logoutForm {
display: inline-block;
}
http://jsfiddle.net/XdQA8/
To solve I added the _LoginPartial.cshtml inside a DIV tag like this :
<div class="navbar-collapse collapse">
<div class="navbar-text navbar-right">
#Html.Partial("_LoginPartial")
</div>