restricting the width of the submenubar in bootstrap - html

I am trying to restrict the width of the submenu items "Certification" and "Training", Currently it is occupying the whole window size.
Here is the code
<div class="navbar navbar-inverse navbar-fixed-top" >
<div class="container" >
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div >
#* #Html.ActionLink("Application name", "Index", "Home", null, new { #class = "navbar-brand" })*#<img src="~/Images/InfosysLogo.png" style="height:70px;width:200px" />
</div>
</div>
<div class="navbar-collapse collapse">
<ul id="nav" class="nav navbar-nav">
<li>#Html.ActionLink("DashBoard", "ExecutiveDashboard", "Charts")</li>
<li>#Html.ActionLink("Engagement Metrics", "EngagementMatrix", "Charts")</li>
<li>#Html.ActionLink("Quality Metrics", "Contact", "Home")</li>
<li>
#Html.ActionLink("People Aspects", "Contact", "Home")
<ul>
<li>#Html.ActionLink("Certifications", "Index", "Certification",null, new { #class = "my-class" })</li>
<li>#Html.ActionLink("Trainings", "Index", "Training", null,new { #class = "my-class" })</li>
</ul>
</li>
<li>#Html.ActionLink("Financials", "BudgetVSActualChart", "Financial")</li>
<li>#Html.ActionLink("Admin", "AdminView", "PMODashboard")</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="navbar-text">Hello, #User.Identity.Name!</li>
</ul>
</div>
</div>
</div>
Any help will be appreciable
Thank you

Since you are loading in bootstrap anyway, you should use the bootstrap grid system. Add for example class="col-lg-3" to your div you want to rescrict in width. You can find more information about the grid system on Bootstrap grid page. This is always a nice way to make your page responsive!

Allright, I found the problem you are having:
The problem is that .nav-collapse has a with of auto.
There are 2 ways you could fix this.
Overwrite the .collapse in your css file like:
.navbar-collapse {
width:250px;
box-shadow: none;
border-top: 0px;
}
You find your bootstrap.css file and look for the following 2 rules:
#media (min-width: 768px) {
.navbar-collapse {
Here you remove the line that says width:auto;
I would advise you to use example 1.
Check out this jsfiddle
Let me know if it works for you!
Cheers

I used the class dropdown to the item on which dropdown will appear and class dropdown-menu in the un ordered list tag and it resolved my issue.
<ul id="nav" class="nav navbar-nav">
<li>#Html.ActionLink("DashBoard", "ExecutiveDashboard", "Charts")</li>
<li>#Html.ActionLink("Engagement Metrics", "EngagementMatrix", "Charts")</li>
<li>#Html.ActionLink("Quality Metrics", "Contact", "Home")</li>
<li class="dropdown">
#Html.ActionLink("People Aspects", "Contact", "Home")
<ul class="dropdown-menu navbar-inverse">
<li>#Html.ActionLink("Certifications", "Index", "Certification")</li>
<li>#Html.ActionLink("Trainings", "Index", "Training")</li>
</ul>
</li>
<li>#Html.ActionLink("Financials", "BudgetVSActualChart", "Financial")</li>
<li>#Html.ActionLink("Admin", "AdminView", "PMODashboard")</li>
</ul>

Related

Bootstrap - reversing my navbar to Right-to-Left

Im trying to make a navbar but I need it to be from Right to Left cause its in Hebrew.
I tried making a responsive Navbar Where all the linked buttons are on the Left and Going Right.
And a Brand on the Right side.
And they collapse on Small devices.
Well I cant get it to reverse and I also sometimes get an issue where on small devices the Brand and the Collapse button collide in the middle of the navbar.
Well I fixed it by adding:
body{
direction: rtl;
}
to my css...
Thanks for the help and sorry for misleading you by my wrong title D:
Maybe you can use media query with the smallest query eg media query
example:
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Left</li>
</ul>
<ul class="nav navbar-nav navbar-center">
<li>Center</li>
<li>Center</li>
<li>Center</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Right</li>
</ul>
</div>
</nav>
#media (min-width: 240px) {
.navbar-nav.navbar-center {
position: absolute;
left: 50%;
transform: translatex(-50%);
}
This work fine for me.
<ul class="nav nav-tabs nav-justified" style="direction: rtl;">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>

In visual studio 2013 mvc, how to have a dropdown list in header using bootstrap and html helper

my requirement is as below.
I have a header with the following links: Home, Destinations, Seasons.
I want the Destinations link to be a drop down list(containing links Attractions and Popular destinations) on hover. I know how to implement this using html, css and bootstrap, but since im using mvc, navigating to the action method in the controller would be a problem.
Below is the code ive got so far. Have no clue how to implement the dropdown list. Please help!
<div class="menu">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">#Html.ActionLink("Home", "Index", "Home")</li>
<li>
<ul class="dropdown-menu" aria-labelledby="dropdownmenu1">
<li>#Html.ActionLink("Activities", "Activities", "Home")</li>
<li>#Html.ActionLink("Popular Destinations","Destinations","Home")</li>
</ul>
</li>
<li>#Html.ActionLink("Seasons", "Seasons", "Home")</li>
</ul>
</div>
</div>
I want the links 'Activities' and 'Popular Destinations' to be in the dropdown list of the header link 'Destinations'. Please advice how to achieve this using bootstrap and html helper actionlink.
You should use-
#Html.DropDownListFor(model => model.YourModelName, listItems, "-- Select Value--")
For more detail, Please refer:-
DropDownList in MVC 4 with Razor
Try this below html
<div class="menu">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">#Html.ActionLink("Home", "Index", "Home")</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Destinations
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>#Html.ActionLink("Activities", "Activities", "Home")</li>
<li>#Html.ActionLink("Popular Destinations","Destinations","Home")</li>
</ul>
</li>
<li>#Html.ActionLink("Seasons", "Seasons", "Home")</li>
</ul>
</div>
</div>

making bootstrap menubar of fix size

I am trying to add dropdown submenu to bootstrap menubar, Submenu appears as soon as i hover on the "people aspect".But when submenu appears it is extending the size of menubar. Is there any way the fix the size of the menubar
Here is the code
<div class="navbar navbar-inverse navbar-fixed-top" >
<div class="container" >
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div >
#* #Html.ActionLink("Application name", "Index", "Home", null, new { #class = "navbar-brand" })*#<img src="~/Images/InfosysLogo.png" style="height:70px;width:200px" />
</div>
</div>
<div class="navbar-collapse collapse">
<ul id="nav" class="nav navbar-nav">
<li>#Html.ActionLink("DashBoard", "ExecutiveDashboard", "Charts")</li>
<li>#Html.ActionLink("Engagement Metrics", "EngagementMatrix", "Charts")</li>
<li>#Html.ActionLink("Quality Metrics", "Contact", "Home")</li>
<li>
#Html.ActionLink("People Aspects", "Contact", "Home")
<ul id="subnav">
<li>#Html.ActionLink("Certifications", "Index", "Certification", new { #class = "my-class" })</li>
<li>#Html.ActionLink("Trainings", "Index", "Training", new { #class = "my-class" })</li>
</ul>
</li>
<li>#Html.ActionLink("Financials", "BudgetVSActualChart", "Financial")</li>
<li>#Html.ActionLink("Admin", "AdminView", "PMODashboard")</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="navbar-text">Hello, #User.Identity.Name!</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
Any help will be appreciable.
Thank you
example try this code of css and check
HTML
<div class="navbar navbar-inverse navbar-fixed-top" >
</div>
CSS
.navbar{
width:980px;
}
HTML
<div class="navbar navbar-inverse navbar-fixed-top" >
</div>
CSS
.navbar{
min-height:90px !important;
}
resolved my issue it set the min height to 90px so when i was hovering on menu item submenu items were not extending my menubar

how customize bootstrap default top fixed nav like one in image below?

I am trying to customize bootstrap default fixed top nav to make it like one in images below. I am using latest twitter bootstrap 3.1.1. If you know please help me. You can even help me with any repository for it. The one in image is from i purchased which is using bootstrap 2x but i want to update it to 3x and use it in another template.
<div class="topHeaderSection">
<div class="header">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<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="index.html"><img src="assets/custom/img/logo.png" alt="My web solution" /></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li class="dropdown">
Services <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
</ul>
</li>
<li>About us</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
You need to take your dropdown button out of the div with the collapse class, and put it into the navbar-header div. Then create an additional navbar-header for the application title.
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Title - manually pull it left-->
<div class="navbar-header pull-left">
#Html.ActionLink("Application name", "Index", "Home", null, new { #class = "navbar-brand" })
</div>
<!-- Buttons that won't collapse - and manually pull right-->
<div class="navbar-header pull-right">
<!-- Your drop down button that is not part of the collapse group -->
<ul class="nav pull-left">
<li class="dropdown pull-right">
Services <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
</ul>
</li>
</ul>
<!-- The normal bootstrap button to show collapsed menu items -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Regular collapsed items -->
<div class="navbar-collapse collapse navbar-right">
<ul class="nav navbar-nav pull-right">
<li>About us</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
Check out this answer to a similar question: https://stackoverflow.com/a/22978968/1721571.
Included in this answer is a link to a fiddle which should help you. I tried it out and it worked well without any changes.
Here's the link if you want to jump straight in. Fiddle: http://jsfiddle.net/nomis/n9KtL/1/
UPDATE
Your additional requirements may require some JavaScript. From my understanding you want the navbar to be static until the user scrolls down to the point where the navbar reaches the top of the window. Then you want it to be fixed.
Add your Contact div above the first navbar element. I have made it a navbar-default so the difference is more clear. You don't have to use the bootstrap nav or container classes. You can create your own and get the style to your liking:
<div class="navbar navbar-default navbar-static-top" style="margin-bottom:0px" role="navigation">
<div class="container">
<div class="text-info">Small div with contact information</div>
</div>
</div>
Now change the original navbar to static to start off with. We will also give it a menu class so we can select it with jQuery:
<div class="navbar navbar-inverse navbar-static-top menu" role="navigation">
For the JavaScript:
$(document).ready(function () {
var menu = $('.menu');
var origOffsetY = menu.offset().top;
function scroll() {
if ($(window).scrollTop() >= origOffsetY) {
$('.menu').addClass('navbar-fixed-top');
$('.body-content').addClass('menu-padding');
} else {
$('.menu').removeClass('navbar-fixed-top');
$('.body-content').removeClass('menu-padding');
}
}
document.onscroll = scroll;
});
Notice how I have added a class to the body-content, this stops the content disappearing behind the navbar-fixed when it changes class.
.menu-padding {
padding-top: 80px;
}
Here is the complete fiddle: http://jsfiddle.net/seanobr/wsNYQ/

Bootstrap 3 navigation bar right margin is not supposed to be -15px

In my web page I have a Bootstrap 3 navbar:
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">Teachlab</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", '#' %></li>
<li><%= link_to "Help", '#' %></li>
<li><%= link_to "Sign in", '#' %></li>
</ul>
</div>
</nav>
<div class="container">
<%= yield %>
</div>
</body>
The problem is that navigation is to close to the edge of the screen. If I remove navbar-fixed-top from the navigation bar, it's working as I want.
Any hints?
Use .container-fluid as of 3.1.1.
The structure is not correct. .navbar-right goes on the .collapse container not on the ul.
SAMPLE: http://jsbin.com/eQIROsE/2/edit
<div class="navbar navbar-fixed-top navbar-default">
<div class="navbar-header">
<a class="navbar-brand" href="#">Project name</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse navbar-right">
<ul class="nav navbar-nav">
<li class="active">Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
<!--/.navbar-collapse -->
</div>
I ended up with overriding following:
.navbar-nav.navbar-right:last-child {
margin-right: 0;
}
But maybe there's another solution?
It's broken and won't fix in 3.x. Hack it.
.navbar-right {
margin-right: 0px;
}
The solution to this could be
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<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="#">Project name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>Default</li>
<li>Static top</li>
<li class="active">Fixed top</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
It worked for me.
I really can't see why you'd have two .navbar-nav.navbar-right. Just wrap the navs in .navbar-right instead.
<div class="navbar-right">
<ul class="nav navbar-nav">...</ul>
<ul class="nav navbar-nav">...</ul>
</div>
I got exactly the same issue today!
According to Bootstrap doc <ul class="nav navbar-nav navbar-right"> is correct.
Like you, I solved the problem by setting the nav navbar-nav navbar-right margin-right to 0px without noticing unwanted effects.
Notice that the margin-right value of .navbar-text.navbar-right:last-child is 0px while .navbar-nav.navbar-right:last-child margin-right value is -15px... Bizarre?
https://github.com/twbs/bootstrap/issues/13325
My not so elegant solution, but does the job very quickly, add a last list item;
<li><span> </span></li>
If you have problem with
margin-right: -15px;
in .navbar-right then just add in your css styles
.navbar-right {
margin-right: 0px;
}
and if this still doesn't work clear your browser from all history when your webstie was running and debug it again. It works :)
(Fixed in asp.net mvc)
I had the same problem in asp.net mvc c#, the way i fix it was by going to Contents/bootstrap.css i located the .navbar{} class and i add it a padding of 5 px,that worked for me.
Heres how it looks when you find it..