0

I am trying to narrow the height of my navbar so that it does not expand (in height) for certain screen sizes or when extra text is added to the navbar.

This is my html:

    <div class="navbar navbar-inverse navbar-fixed-top" id="navbar-site">
    <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>
            @Html.ActionLink("Website Name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
        </div>
        <div class="navbar-collapse collapse navbar-options">
            <ul class="nav navbar-nav">
                <li>@Html.ActionLink("Home", "Index", "Home")</li>
                <li>@Html.ActionLink("About", "About", "Home")</li>
                <li>@Html.ActionLink("Link", "Link", "Link")</li>
                <li>@Html.ActionLink("Link", "Link", "Link")</li>
                <li>@Html.ActionLink("Link", "Link", "Link")</li>
                <li>@Html.ActionLink("Link", "Link", "Link")</li>
            </ul>
            @Html.Partial("_LoginPartial")
        </div>
    </div>
</div>

My CSS:

#navbar-site {
    height: 15px;
}

I have tried adding a height and max height css to my navbar but still no luck.

Update: here is a running version of my problem on bootply. Note what happens when the window is made smaller, the height is expanded and the links nestle beneath.

1 Answers1

0

You need to do 2 things to get a Bootstrap 3 navbar to be less than 50px high.

  1. Set the .navbar height and min-height to your desired height.
  2. Remove any unwanted padding/margins from the elements inside the navbar.

Here's an example with a simplified version of your HTML: https://jsfiddle.net/caleyshemc/ns0674mp/

Note that you will also have to make whatever's inside your LoginPartial smaller as well.

polyp
  • 78
  • 1
  • 9
  • Will this solve the same issue I have found in this example here: https://getbootstrap.com/examples/navbar/ –  Apr 17 '17 at 22:00
  • When the page is minimized before the toggle appears, the links go below and expand the height of the navbar –  Apr 17 '17 at 22:00
  • 1
    @gbear96 That happens because there is too much on the navbar to fit the page width. It can be fixed by putting fewer links inside the navbar, or changing the collapse breakpoint (see http://stackoverflow.com/questions/20817956/change-collapse-breakpoint-in-bootstrap-3-0). – polyp Apr 17 '17 at 22:04