Bootstrap 3 nav collapse menu - anchor always on the right - css

I have this Bootstrap head menu, and i want the Login anchor, allways on the right, after the UL nav, and collapsed button.
I've tried a .pull-right on that, but didn't work.
<header id="main-header">
<nav class="navbar navbar-default navbar-custom navbar-fixed-top" role="navigation">
<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="#">
<img alt="Logo" src=""></a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul id="nav" class="nav navbar-nav nav-pills navbar-right">
<li>home</li>
<li class="dropdown">link2</li>
<li class="">link3</li>
<li class="">link4</li>
<li class="">link4
<ul class="dropdown-menu">
<li>sublink</li>
<li>sublink2</li>
</ul>
</li>
</ul>
<a href="#" class="btn btn-primary">
Login</a></div>
</nav>
</header>

Because there's problem with jsfiddle currently, I'll paste modified code here:
<header id="main-header">
<nav class="navbar navbar-default navbar-custom navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<div class="pull-right">
<a id="rightAnchor" href="#" class="btn btn-primary">
Login</a>
</div>
<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="#">
<img alt="Logo" src=""/></a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul id="nav" class="nav navbar-nav nav-pills navbar-right">
<li>home
</li>
<li class="dropdown">link2
</li>
<li class="">link3
</li>
<li class="">link4
</li>
<li class="">link4
<ul class="dropdown-menu">
<li>sublink</li>
<li>sublink2</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
</header>
Firsltly, you're missing one closing div, just before the nav closing tag. Next, I've added div with pull-right class just before button in navbar-header. Finally, add some margins so that login anchor would look same as menu:
#rightAnchor {
margin-top: 8px;
margin-right: 15px;
margin-bottom: 8px;
}
UPDATE: I did not check how it behaves when we have different resolution. How about this: we create 2 login anchors and controll theirs appearance with media queries? With this HTML would look like this:
<header id="main-header">
<nav class="navbar navbar-default navbar-custom navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<div id="rightAnchorMobile" class="pull-right">
<a href="#" class="btn btn-primary">
Login</a>
</div>
<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="#">
<img alt="Logo" src=""/></a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<div id="rightAnchor" class="pull-right">
<a href="#" class="btn btn-primary">
Login</a>
</div>
<ul id="nav" class="nav navbar-nav nav-pills navbar-right">
<li>home
</li>
<li class="dropdown">link2
</li>
<li class="">link3
</li>
<li class="">link4
</li>
<li class="">link4
<ul class="dropdown-menu">
<li>sublink</li>
<li>sublink2</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
</header>
And CSS:
#media screen and (min-width:768px) {
#rightAnchorMobile {
display: none;
}
}
#media screen and (max-width: 768px) {
#rightAnchor {
display: none;
}
}
#rightAnchorMobile > a {
margin-top: 8px;
margin-right: 15px;
margin-bottom: 8px;
}
#rightAnchor > a {
margin-top: 8px;
margin-left: 15px;
margin-bottom: 8px;
}

Related

Navigation issue HTML and CSS

I'm having some issue with my navigation bar. It turns out like this:
But I want it too look like this:
The code looks a little like this:
<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
<div class="container topnav">
<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 topnav" href="#" target="_blank">Name</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
This is a plain CSS implementation with flexbox wihtout knowing your other CSS stuff:
.navbar > .container{
display:flex;
flex-flow:row wrap;
justify-content: space-between;
}
.navbar-right{
display:flex;
flex-flow:row wrap;
justify-content: flex-end;
}
.navbar-right li{
list-style:none;
}
.navbar a{
display:block;
padding:0.3em 1em 0.5em 1em;
}
<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
<div class="container topnav">
<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 topnav" href="#" target="_blank">Name</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>

In Bootstrap, how would you change background color of dropdown menu header whose parent is transparent?

I searched the whole Internet, but none of the solutions work.
What I am trying to do?
I want to change the background color of the dropdown menu header.
https://ibb.co/cthhTk
HTML:
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<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="#"> Blackbird </a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li> Search </li>
<li class="dropdown">
Sign In/Up <b class="caret"></b>
<ul class="dropdown-menu" class="dropdownMenu">
<li> Sign Up </li>
<li> Sign In </li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-left">
<li class="seperator"></li>
<li> Article </li>
<li> Contact </li>
</ul>
</div>
</div>
</nav>
CSS:
/* Neither does this work: */
.dropdown {
background-color: #E32636;
}
/* Nor this: */
/* .navbar .navbar-default .navbar-nav .dropdown-menu li > a {
background-color: #E32636;
}
*/
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<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="#"> Blackbird </a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li> Search </li>
<li class="dropdown">
Sign In/Up <b class="caret"></b>
<ul class="dropdown-menu" class="dropdownMenu">
<li> Sign Up </li>
<li> Sign In </li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-left">
<li class="seperator"></li>
<li> Article </li>
<li> Contact </li>
</ul>
</div>
</div>
</nav>
I have added an ID to the hyperlink which opens the signIn/signOut menu.
and then add a background color to it, so
#authentication{
background-color: #f60;
}
or, if you really dont wanna add a new ID or a class, you can query the element as something like,
navbar navbar-collapse>ul>li:nth-child(2)>a{
background-color: #f60;
}
Check this working code:
.navbar-nav > li.dropdown.open a, .navbar-nav > li.dropdown.open a:focus, .navbar-nav > li.dropdown.open a:hover{
background-color: #E32636;
}
.navbar-nav > li > .dropdown-menu {
background-color: #E32636;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<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="#"> Blackbird </a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li> Search </li>
<li class="dropdown">
Sign In/Up <b class="caret"></b>
<ul class="dropdown-menu" class="dropdownMenu">
<li> Sign Up </li>
<li> Sign In </li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-left">
<li class="seperator"></li>
<li> Article </li>
<li> Contact </li>
</ul>
</div>
</div>
</nav>
You can also check this working Fiddle

Stop button going full width and keep navbar icon to the left

When the screen size is moved to sm, then the logout button width takes up the whole screen and the nav bar hamburger icon goes in the middle:
This is how it looks when it's normal:
Here is the code for it:
<!-- navbar -->
<nav class="navbar navbar-toggleable-sm bg-info navbar-inverse">
<div class="container">
<button class="navbar-toggler" data-toggle="collapse" data-target="#mainNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainNav">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">Home</a>
<a class="nav-item nav-link" href="#">About</a>
<a class="nav-item nav-link" href="#">Training</a>
<a class="nav-item nav-link" href="#">LOGOUT</a>
</div>
</div>
</div>
Logout
</nav>
check out that code. It works
#media(max-width:777px){
.btn-danger{
max-width:70px!important;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<nav class="navbar navbar-toggleable-sm bg-info navbar-inverse">
<div class="container">
<button class="navbar-toggler" data-toggle="collapse" data-target="#mainNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainNav">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">Home</a>
<a class="nav-item nav-link" href="#">About</a>
<a class="nav-item nav-link" href="#">Training</a>
<a class="nav-item nav-link" href="#">LOGOUT</a>
</div>
</div>
</div>
Logout
</nav>
here you also have it on codepen.io
https://codepen.io/hansfranz/pen/owmVod
What I did was setting up a media Query here you can define the behavior for a specific width.
Hope that helps if not leave a comment :)
Using flexbox to organize the layout.
#media screen and (max-width:640px) {
nav.navbar,
.container {
display: flex;
justify-content: flex-start;
align-items: center;
margin: 0!important;
}
nav .btn.btn-danger {
margin-left: auto;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<!-- navbar -->
<nav class="navbar navbar-toggleable-sm bg-info navbar-inverse">
<div class="container">
<button class="navbar-toggler" data-toggle="collapse" data-target="#mainNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainNav">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">Home</a>
<a class="nav-item nav-link" href="#">About</a>
<a class="nav-item nav-link" href="#">Training</a>
<a class="nav-item nav-link" href="#">LOGOUT</a>
</div>
</div>
</div>
Logout
</nav>
You should not leave the logout link outside the navbar div. Here is an example that could help.
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Link Button</li>
</ul>
</div>
</div>
</nav>

Bootstrap Brand Image Showing too large

Perhaps its my css but my code should show the image in the header at a fixed size. However, it looks like it may be outside of the div. Heres the code.
<div class="row">
<div class="col-md-12 top navbar-fixed-top">
<div class="col-md-6">
<nav class="navbar navbar-default" role="navigation">
<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="#"><img class="img-responsive" src="http://dev-httpwwwrestechsyscom.pantheonsite.io/sites/all/themes/myWay/logo.png"></a>
</div></nav></div>
<div class="col-md-6">
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<ul class="menu"><li class="first expanded dropdown active">About Us <span class="caret"></span><ul class="dropdown-menu"><li class="first leaf active">Mission Statement</li>
<li class="leaf">Meet Our Team</li>
<li class="leaf">Testimonials</li>
<li class="last leaf">Sample Athletes Profile</li>
</ul></li>
<li class="leaf">Eligibility</li>
<li class="expanded dropdown">Recruiting <span class="caret"></span><ul class="dropdown-menu"><li class="first leaf">Recruiting FAQ</li>
<li class="last leaf">Recruiting Info</li>
</ul></li>
<li class="last leaf">Services</li>
</ul><li class="active"></li>
</ul>
</div>
</div></div></div>
You can fix it in this way. Just add desired height to brand image and width will be auto based on height. For example:
.navbar-brand img {
height: 30px;
}
You can add a max-height: 100% to the .navbar-brand img element and it will contain the image inside of .navbar-brand. The height of .navbar-brand is 50px from bootstrap's css, so to make it bigger than that, change the height of .navbar-brand
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<style>
.navbar-brand img {
max-height: 100%;
}
/* add/change this if you want to make the navbar brand area bigger */
.navbar-brand {
height: 100px;
}
</style>
<div class="row">
<div class="col-md-12 top navbar-fixed-top">
<div class="col-md-6">
<nav class="navbar navbar-default" role="navigation">
<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="#"><img class="img-responsive" src="http://dev-httpwwwrestechsyscom.pantheonsite.io/sites/all/themes/myWay/logo.png"></a>
</div>
</nav>
</div>
<div class="col-md-6">
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<ul class="menu">
<li class="first expanded dropdown active">About Us <span class="caret"></span>
<ul class="dropdown-menu">
<li class="first leaf active">Mission Statement</li>
<li class="leaf">Meet Our Team</li>
<li class="leaf">Testimonials</li>
<li class="last leaf">Sample Athletes Profile</li>
</ul>
</li>
<li class="leaf">Eligibility</li>
<li class="expanded dropdown">Recruiting <span class="caret"></span>
<ul class="dropdown-menu">
<li class="first leaf">Recruiting FAQ</li>
<li class="last leaf">Recruiting Info</li>
</ul>
</li>
<li class="last leaf">Services</li>
</ul>
<li class="active"></li>
</ul>
</div>
</div>
</div>
</div>

bootsrap nav not responding well when layout changes

<div class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-brand pull-left">
<a href="#" class="pull-left">
<img width="150" height="45" class="navbar-left" src="Intellicell_files/IntelliCell-Logo.png" /></a>
</div>
<button class="navbar-toggle pull-right" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse navHeaderCollapse pull-right">
<ul class="nav navbar-nav navbar-right navbar-text">
<li><a id="homeLink" href="#" data-target="home_container">Home</a></li>
<li><a id="contractslink" href="Contracts.aspx">Contracts</a></li>
<li><a id="accounts" href="AccountHistory.aspx">Account History</a></li>
<li>Contact Us</li>
<li><a id="refer" href="#">Refer a Friend</a></li>
<li><a id="tracker" href="#">Incentive Tracker</a></li>
</ul>
</div>
</div>
<div class="center-block" id="divider">
<div class="nav-divider">
<h4 class="text-center">HOME</h4>
<%--<asp:Button Text="Logout" CssClass="btn btn-group-sm form-control" ID="btnLogOut" runat="server" align="right" OnClick="btnLogOut_Click"/>--%>
</div>
</div>
</div>
the problem comes when I test the Navbar on a tablet and that causes the navbar to go under the logo that i have put there, so i was wondering if there is a way of making sure that the nav logo and the nav options are always on the same line. i am using bootstrap by the way
One option is to reduce the padding between your links.
Also, see the Docs regarding how to structure a default navbar.
.navbar .navbar-brand {
padding-top: 3px;
}
#media (min-width: 768px) {
.navbar .navbar-nav > li > a {
padding-left: 8px;
padding-right: 8px;
}
}
<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-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navHeaderCollapse" aria-expanded="false"> <span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img width="150" height="45" src="http://placehold.it/150x45/f00" />
</a>
</div>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li><a id="homeLink" href="#" data-target="home_container">Home</a>
</li>
<li><a id="contractslink" href="Contracts.aspx">Contracts</a>
</li>
<li><a id="accounts" href="AccountHistory.aspx">Account History</a>
</li>
<li>Contact Us
</li>
<li><a id="refer" href="#">Refer a Friend</a>
</li>
<li><a id="tracker" href="#">Incentive Tracker</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="navbar navbar-default navbar-static-top">
<div class="container">
<button class="navbar-toggle pull-right" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse navHeaderCollapse">
<div class="navbar-brand">
<a href="#">
<img height="45" class="navbar-left" src="http://i.ytimg.com/vi/PDfWeUP09TA/hqdefault.jpg" /></a>
</div>
<ul class="nav navbar-nav navbar-right navbar-text">
<li><a id="homeLink" href="#" data-target="home_container">Home</a></li>
<li><a id="contractslink" href="Contracts.aspx">Contracts</a></li>
<li><a id="accounts" href="AccountHistory.aspx">Account History</a></li>
<li>Contact Us</li>
<li><a id="refer" href="#">Refer a Friend</a></li>
<li><a id="tracker" href="#">Incentive Tracker</a></li>
</ul>
</div>
</div>
<div class="center-block" id="divider">
<div class="nav-divider">
<h4 class="text-center">HOME</h4>
<%--<asp:Button Text="Logout" CssClass="btn btn-group-sm form-control" ID="btnLogOut" runat="server" align="right" OnClick="btnLogOut_Click"/>--%>
</div>
</div>
</div>
ul li a{
padding-left: 10px !important;
padding-right: 10px !important;
}
Im not frontend, but it should help :)
I wrapped img and ul by div, and thru smaller padding get img to row with menu.
Its just a suggest, problem is, ul li a is too big, and push img up

Resources