Increasing the height of the Bootstrap Collapsed "mobile" navigation menu? - html

I am struggling to get the mobile collapsed drop down nav to increase in height. Currently it is stuck at about 340px and I need it to expand to fit the menu items being contained within the collapsed nav. I have searched tirelessly on Google and here to find an answer but none of them seem to make an impact, even when I use !important.
Here's a screenshot of what I am talking about to avoid any confusion. The blue bordered area that I added to the screenshot is what I am talking about. This seems to be set to a static height and I need it to extend about another 50px-100px for this particular application. I did not show code here because I am hoping to just see the "best way" to change the default height for my future reference.
Thanks for the help!
EDIT: I did not submit code because right now it's just the default bootstrap nav code so I didn't think I needed to reference it.
Here's the code, I am just using a simple generic startbootstrap.com template here.
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-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 page-scroll" href="#page-top">Start Bootstrap</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<!-- Hidden li included to remove active class from about link when scrolled up past about section -->
<li class="hidden">
<a class="page-scroll" href="#page-top"></a>
</li>
<li>
<a class="page-scroll" href="#about">About</a>
</li>
<li>
<a class="page-scroll" href="#services">Services</a>
</li>
<li>
<a class="page-scroll" href="#contact">Contact</a>
</li>
<li>
<a class="page-scroll" href="#about">About</a>
</li>
<li>
<a class="page-scroll" href="#services">Services</a>
</li>
<li>
<a class="page-scroll" href="#contact">Contact</a>
</li>
<li>
<a class="page-scroll" href="#about">About</a>
</li>
<li>
<a class="page-scroll" href="#services">Services</a>
</li>
<li>
<a class="page-scroll" href="#contact">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
I have no custom CSS yet as this is the first thing I am trying to change and don't know where in the CSS the dropdown nav should be edited.

Without seeing the code it is difficult to say what is impacting the height. If you add more <li>'s to the menu, does it expand?
If not, there could be a static height or max-height css property applied to the .dropdown-menu
Editing for improvement:
It looks like either of these elements;
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
has a height or max-height and overflow:auto property.
Inspect these elements in chrome to see if this is the case. Then, set height:auto; and/or adjust the max-height property to allow for increased height for that element.
You can set these in your custom CSS file and they will override Bootstrap's style. Just ensure that your CSS file is loaded after the Bootstrap CSS file.
If you can post a link I can look at it and provide the exact code needed to make the changes.

I had the same problem with my mobile collapsed drop-down navigation displaying a scrollbar rather than expanding to show all the navigation links. My solution was to hide the scrollbar then add pixels to the bottom of my data-target div.
You should be able to hide the scrollbar using:
.navbar-collapse.in {
overflow: hidden;
}
Then you can add the extra pixels needed at the bottom by adding padding to the data-target div when sized for mobile devices:
#media (max-width: 768px) {
.navbar-ex1-collapse {
padding-bottom: 50px;
}
}

Related

How to make bootstrap's navbar display horizontally

I am following the example to use the Navbar from http://getbootstrap.com/components/#navbar-default, however, I am having problem to make it display horizontally like in the example. The code below is the same from the page. What am I missing to make it to display horizontally?
<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap#3.3.5" data-semver="3.3.5" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body id="bs-example-navbar-collapse-1">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<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="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span>
</li>
<li>Link
</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li role="separator" class="divider"></li>
<li>Separated link
</li>
<li role="separator" class="divider"></li>
<li>One more separated link
</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link
</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li role="separator" class="divider"></li>
<li>Separated link
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
</body>
</html>
Try using ul class="nav nav-pills navbar-right".
I am not 100% sure that "my" problem was exactly the same as the original posters, but it looks very similar and the same solution could apply.
In my case, the problem manifested when the navbar was used within an Angular application with the "developer tools" on the side. This was reducing the width of the page made available to bootstrap, below a certain threshold (see below), which in turn made the navbar items to show on a column instead of a row.
The outermost navbar definition, as of the documentation sample, looked like this:
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
...
</div>
</nav>
After I checked the various element classes / styles in the browser, as well as the Bootstrap documentation, it seems that the following constraints apply:
The layout of the li elements is not directly controlled by the parent ul, but by the main nav element.
This one may bear a flex-direction: row style, and in this case the navbar items are shown horizontally, exactly as in the documentation samples. However, this style is conditioned by a minimum page width.
If the page is not wide enough, this style is not applied, the navbar is shown as collapsed and the "Toggle collapse" button is shown.
When expanding the navbar via the "Toggle collapse" button, the navbar items are always shown vertically, no matter how wide the page is.
Now the anomaly seems to be related to Bootstrap mistakenly deciding that the navbar items won't fit within a given page width, while common sense says they will. (In my case, it switched to collapsed navbar when the items would only need 40% of the available page width).
As stated by the documentation page, this is controlled (in the snippet above) via the navbar-expand-lg class, and more specifically the "lg" suffix. This explicitly refers to a specific display width. Changing this suffix (towards lower widths) triggers the presentation switch - from expanded to collapsed - in a way more appropriate for the actual navbar content. Concretely, in my case changing to navbar-expand-sm made the navbar behave as expected as the page gets wider or narrower.
At first view, this solution could affect the page portability across devices. However, I don't think this is the case because it is not about specifying an expected page with, but a minimum page width to accommodate the navbar - which does not depend on the device.
From the way I had read your question, I get that you are trying to get it vertically instead of horizontally. It's at least an assumption from your code example that is already horizontal. :)
A nav list with the class flex-column should to the trick for the list itself. Found this over at the Bootstrap documentation itself under there available styles. An example of this list itself could look something like this:
<ul class="nav flex-column nav-link">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
<form class="my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</ul>
Most of the things bootstrap has for a navbar seem to work with this. This is at least with the things I have used until now.

Fill Remaining Width of parent

I have a navigation menu, with a collapsible list of child pages. Except the dropdown element needs to have an accessible page on the same line as well. This is what I have so far.
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-lg-2">
<div class="navbar navbar-default navbar-fixed-side">
<ul class="nav" id="side-menu-0">
<li id="menu-template" class="nav">
<i class="fa fa-dashboard fa-fw"></i>Dashboard
</li>
<li id="menu-template-top" class="nav" role="menu">
Google
<span class="caret"></span>
<ul id="menu-template-top-sub" class="collapse nav nav-second-level">
<li class="nav">
Flot Charts
</li>
<li class="nav">
Morris.js Charts
</li>
</ul>
<!-- /.nav-second-level -->
</li>
</ul>
</div>
</div>
Here is the working fiddle, so you can see what I am trying to do. I want the Link for "Google" to stretch across to the right, like the "Dashboard" link can do. Working Fiddle
A simple fix for this is to do this:
Google
You could of course externalize this to a stylesheet if you wish.
The 40px in the calc(100% - 40px) is the width of your dropdown caret.
This makes it stretch all the way to the dropdown-expansion button.
Add display block to your <a> tag, instead of display inline-block. Block elements will span the entire width.

bootstrap 4 change navbar height causing navbar items to not be vertically centered

I have a bootstrap 4 navbar like this:
<nav class="navbar navbar-light bg-faded navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<!-- Toggle Button -->
<button type="button" class="navbar-toggler hidden-md-up"
data-toggle="collapse"
data-target="#nav-content"
aria-expanded="false">
<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="#">THE VEGAN REPOSITORY</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-toggleable-md" id="nav-content">
<ul class="nav navbar-nav pull-xs-right">
<li class="nav-item">
<a class="nav-link" href="#home_page_footer">
<h5 class=" nav-item clickable white-text medium-text
right-text">
ABOUT
</h5>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#home_page_footer">
<h5 class=" nav-item clickable white-text medium-text
right-text">
BLOG
</h5>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://www.w3schools.com">
<h5 class=" nav-item clickable white-text medium-text
right-text">
LOGIN
</h5>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://www.w3schools.com">
<h5 id=" sign-in-button" class="nav-item clickable
medium-text right-text">
SIGN UP FREE
</h5>
</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<nav class="navbar navbar-light bg-faded">
<!-- Toggle Button -->
<button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#nav-content">
</button>
</nav>
I'd like to change the height of the navbar, but when I do, the links are no longer vertically centred.
70px
I have tried line-height, and flexbox options such as
nav {
background-color: $brand-red;
height:70px;
display: flex;
align-items: center;
}
which does:
my only css used for the whole navbar is this:
nav {
background-color: #fc4747;
height: 70px;
display: flex;
align-items: center; }
How do I vertically centre the navbar items if the navbar is 70px tall? The default height of a navbar is a bit smaller, around 50px.
So I figured I would address a few things here but first as to your question. If you just want to change the height of the navbar instead of adding a specific height to the nav you could just add extra padding to the navbar to give you your desired height and then you wouldn't have to change a bunch of css throughout the rest of the navbar. So doing this should give the navbar a height of 70px.
.navbar{padding:1rem}
Here is a fiddle of everything I address in this post in action Fiddle Demo
In this fiddle demo I have also added some responsive styles for stacking the navbar links at your collapse width.
Next If you are going to set a background color to the nav there is no reason to use the bg-faded class to the nav as this just gives you the background color for the nav so you can remove that class from your nav.
Then I see in your classes for your nav links you have a white-text class. If you want white text for your navbar your can just use the class of navbar-dark and this will give you lighter text for the navbar instead of using navbar-light. Just figured I would point that out.
Next In bootstrap 4 there is no navbar-header class so this is not necessary unless you are planning on custom styling something here. And the navbar-toggler button is different in bootstrap 4 there are no icon-bar spans they just use the html code for this now ☰
Note: Addressing a huge pet peeve of mine you have h5 tags in your navbar. Not sure why this is but I see people doing this a lot. H tags are supposed to be used in order from h1 down to h6 and are supposed to be directly related to the page that you are on and not for the entire site. If you have a good reason for this practice then by all means keep them there but I am not sure why I see people do this all of the time. To me it is a bad practice just figured I would address this.

Bootstrap collapsed navbar showing empty

When I click on the hamburger menu in my nicely collapsed bootstrap navbar on my phone, the layout slides to the side as expected, but shows me an empty white (or whatever body background colour I have) bar instead of the navigation. Closer inspection with firebug showed that upon clicking the button, some classes got changed on the navbar-collapsebut it remains tagged as invisible.
I have recompiled Bootstrap from LESS to change the point at which it collapses, but the issue seems persistent even with 'vanilla' bootstrap.
Code:
<nav class="navbar transparent navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header" style="padding-right: 0px; min-width: 50px;">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigation-example-2">
<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 hidden-xs hidden-sm" href="index.html"><span class="glyphicon glyphicon-home" style="padding-right: 0px;"></span></a><a class="navbar-brand hidden-lg hidden-md" href="index.html">De Fijnkost</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navigation-example-2">
<ul class="nav navbar-nav navbar-right">
<li>
Fijne Vleeswaren
</li>
<li>
Bereide Gerechten
</li>
<li>
Eigen salades
</li>
<li>
Kazen & Kaasschotels
</li>
<li>
Belegde Broodjes
</li>
<li>
Contact
</li>
<li>
Nieuws
</li>
<li class="dropdown">
<a class="dropdown-toggle btn btn-white btn-fill" data-toggle="dropdown" href="#">Bestel <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>
Kaasschotel
</li>
<li class="disabled">
Broodjes
</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid-->
</nav>
Same thing happens on pages without the transparent or navbar-fixed-top class. transparent is added by my CSS. Page is visible on defijnkost.be
Your .navbar-collapse is set to display: none !important as far as I can see.
If you set it to display: block in your mobile view media query it should show up just fine.

How to: Non collapsing navigation items Bootstrap 3

I have searched high and low for this, on SO too but didn't find the "correct" answer.
Just figured it out myself.. Thought to share this, hope it helps someone..
Problem with BS3 is that it's Mobile first, which is a good thing, usually.. It's just that I need a few "default" options in the navbar regardless of the collapse state. Just like BS2.
So how can we do this?
One thing is obvious looking at the html code, the .navbar-header stays where it is, it doesn't collapse. Another thing, the magic collapse button has some way of hiding itself, probably CSS but hey, the idea is to abstract this layer so we don't have to worry about it..
But we can take advantage of this, let's place the links I want to show in there, they won't collapse.
What you will see is that your list items will end up vertically, that's not what you want.. So why does it do that?
Well.. If you use Firebug or some other development inspector, you will find that these items have been set to display : block;, that is making them the width of the screen pushing each next item down.
We need to change that behaviour. So let's add a new class to the ul that we can define in our custom CSS. I named it no-collapse but you can name it whatever you want..
<nav role="navigation" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" data-toggle="collapse" data-target="#bs-navbar-collapse" class="navbar-toggle">
<span class="sr-only">Hamburger menu</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- THIS IS WHERE THE MAGIC HAPPENS! -->
<ul class="nav navbar-nav no-collapse">
<li>Apple
</li>
<li>Banana
</li>
</ul>
</div>
<!-- THE STUFF IN THIS DIV WILL COLLAPSE.. -->
<div id="bs-navbar-collapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown">More Fruits <b class="caret"></b>
<ul class="dropdown-menu">
<li class="dropdown-header">Citrus</li>
<li>
Lemon
</li>
<li>
Orange
</li>
<li class="divider"></li>
<li class="dropdown-header">
Also a fruit
</li>
<li>
Tomato
</li>
</ul>
</li>
<li class="dropdown">Veggies <b class="caret"></b>
<ul class="dropdown-menu">
<li class="dropdown-header">Green stuff</li>
<li>
Spinache
</li>
<li>
Lettuce
</li>
<li class="divider"></li>
<li class="dropdown-header">Other stuff</li>
<li>Carrot
</li>
<li>Romenesko broccoli
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
This works
</li>
</ul>
</div>
</div>
</nav>
You'll need a modification, add a CSS (or LESS/SASS) after the bootstrap style sheets.
Add this CSS:
.no-collapse li, .no-collapse li a
{
text-align : center;
float : none;
display : inline-block;
}
Now in Bootply it would look like this: http://www.bootply.com/render/133885 source here:http://www.bootply.com/133885
Now we can have the healthy Apple and Banana on the screen on our mobile devices without resorting to the hamburger menu!