26725

Bootstrap navbar with variable and fixed width buttons?

Question:

I'm trying to make a navbar with Bootstrap that has a brand logo on the left, a couple of variable width links in the middle, and some fixed width buttons on the right. I want everything on one line, and the variable width buttons to just fit in whatever space is available.

See here: <a href="https://jsfiddle.net/wfu6yxqd/" rel="nofollow">https://jsfiddle.net/wfu6yxqd/</a>

the 2 fixed width buttons should be to the right of the variable width links

I don't need Bootstrap's built in navbar collapse behaviour so not needed in my navbar definition (I am implementing my own custom collapse at certain screensizes)

Many thanks for any help!

Code:

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="navbar-header"> <a class="navbar-brand" href="#">Brand</a> <ul class="nav nav-justified"> <li><a href="">Variable width link 1</a></li> <li><a href="">Variable width link 2</a></li> </ul> </div> <div> <!-- class="navbar-header" ?? --> <a class="btn btn-xs btn-default">Fixed width button</a> <div class="btn-group"> <button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">FW drop down&nbsp;&nbsp;<span class="caret"></span></button> <ul class="dropdown-menu" role="menu"> <li><a href="#">Menu item 1</a></li> <li><a href="#">Menu item 2</a></li> </ul> </div> </div> </nav>

Answer1:

Here's one way to go: you can create a div outside/after the navbar-nav section for your buttons and conform that section to the navbar.

*I left the collapsible function in place since I image you'll have something for mobile navigation that will have similar elements to work around.

See example

<pre class="snippet-code-css lang-css prettyprint-override">body, html { margin-top: 75px; } .navbar.navbar-custom { list-style: none; background: #444; line-height: 60px; margin: 0; height: 60px; } .navbar.navbar-custom .navi { display: table; width: 100%; list-style: none; text-align: center; } .navbar.navbar-custom .navi > li { display: table-cell; cursor: pointer; } .navbar.navbar-custom .navi > li > a { text-align: center; text-decoration: none; color: #fff; } .navbar.navbar-custom .logo-brand { margin-left: 15px; color: #fff; text-decoration: none; } .navbar.navbar-custom .btn-nav { text-align: right; } .navbar.navbar-custom .btn-nav .btn.btn-black { height: 50px; border-radius: 0; background: #444; color: #fff; border: none; outline: none; box-shadow: none; } .navbar-custom .btn-group .dropdown-menu, .navbar-custom .btn-group .dropdown-menu:hover, .navbar-custom .btn-group .dropdown-menu:focus { left: auto; right: 0; border: none; background: #444; border-radius: 0; } .navbar-custom .btn-group .dropdown-menu > li > a { color: #fff; } .navbar-custom .btn-group .dropdown-menu > li > a:hover { background: #222; } .no-gutter >[class*='col-'] { padding-right: 0; padding-left: 0; } <pre class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> <nav class="navbar navbar-custom navbar-fixed-top"> <div class="container-fluid"> <div class="row no-gutter"> <div class="col-xs-2"><a class="logo-brand" href="#">Logo Brand</a> </div> <div class="col-xs-8"> <ul class="navi"> <li><a href="#">Link 1</a> </li> <li><a href="#">Link 2</a> </li> </ul> </div> <div class="col-xs-2"> <div class="btn-nav"> <div class="btn-group" role="group" aria-label="..."> <button type="button" class="btn btn-black">1</button> <div class="btn-group" role="group"> <button type="button" class="btn btn-black dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">2 <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="#">Button link 1</a> </li> <li><a href="#">Button link 1</a> </li> </ul> </div> </div> </div> </div> </div> </div> </nav> <div class="container">

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

</div>

Answer2:

How about this <a href="https://jsfiddle.net/t58f873j/" rel="nofollow">https://jsfiddle.net/t58f873j/</a>

<div class="container-fluid"> <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="row"> <div class="col-xs-2"> <a class="navbar-brand" href="#">Brand</a> </div> <div class="col-xs-6 text-center"> <ul class="nav nav-justified"> <li><a href="">Variable width link 1</a></li> <li><a href="">Variable width link 2</a></li> </ul> </div> <div class="col-xs-4"> <a class="btn btn-xs btn-default">Fixed width button</a> <div class="btn-group"> <button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">FW drop down&nbsp;&nbsp;<span class="caret"></span></button> <ul class="dropdown-menu" role="menu"> <li><a href="#">Menu item 1</a></li> <li><a href="#">Menu item 2</a></li> </ul> </div> </div> </div> </nav>

Recommend

  • Cast While Looping Over Dictionary in Swift
  • CSS overflow with long URL
  • Regex: Search for verb roots
  • How do I use Java generic wildcards with methods taking more than one generic parameter?
  • How do one only submit click event (div), when using jquery live function?
  • Parallelizing random forests
  • Bootstrap navbar stays expanded on route change
  • How do I include screenshots of the full page in my serenity report (and not only of the viewport) u
  • Position Fixed in Chrome
  • richtextbox to string
  • how to display   in Mozilla using XSL.
  • Warning: strpos() expects parameter 1 to be string, resource
  • Client side validation mvc dropdown
  • Caret disappears when the background of a textbox is gray in wpf
  • Pre-populated SQLite Database not reading properly in Android Studio
  • Angular - routerLinkActive and queryParams handling
  • Deploying a CodeRush plugin from the Community Site
  • Is it possible to get the word under the mouse cursor in a ``?
  • IE10 strips out hashtag from the URL
  • Aptana 3 remove bundle (jquery)
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • How to override value that appears in a dropdown in the rails_admin gem
  • Uncaught TypeError: $(…).select2 is not a function
  • Custom preprocessing in caret
  • How do I include a SWC in an AS2 Flash project?
  • Bypass multiple inheritance in Java
  • wxPython: displaying multiple widgets in same frame
  • Insert into database using onclick function
  • Deleting and Updating values from a cusrsor adapter
  • Window Size for Mac application
  • SSO with signing and signature validation doesn't work
  • Web-crawler for facebook in python
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Circular dependency while pushing http interceptor
  • Comma separated Values
  • Linker errors when using intrinsic function via function pointer
  • Error creating VM instance in Google Compute Engine
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET