Change CSS of parent element when child element is clicked using JQuery - html

I am trying to change the CSS of a parent image (navbar's border) when the mobile hamburger menu is clicked open, then for it to return back again when clicked again/menu closed.
I have tried to target the navbar with the border using both .parent and .find selector options, but I cannot get either to work. I think I am close, but I'm struggling to work out what's going wrong. Thank you for your help.
$(".navbar-toggler").click(function(){
$(this).find('.navbar').addClass("is-clicked");
$(this).find('.navbar').removeClass("is-clicked");
});
.navbar {
position: relative;
z-index: 98;
border-bottom: 4px solid #000000;
margin-left: 40px;
margin-right: 40px;
color: #000000;
height: 100px;
}
.navbar.is-clicked {
border-bottom: red;
}
.navbar-toggler {
font-size: 32px;
color: black;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar navbar-expand-lg">
<div class="container-fluid nav-container">
<a class="navbar-brand" href="index.html">ABC.</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="toggler-icon"><i class="fas fa-bars"></i>
</span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item nav-item-about p-nav">
<a class="nav-link" aria-current="page" href="about.html">About</a>
</li>
<li class="nav-item p-nav">
<a class="nav-contact" href="mailto:michellelclement#gmail.com?subject=Hello from your portfolio!">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

That is because when you use $(this).find('.navbar'), it only searches for the element with the class navbar inside the element.
If you want to search outwards, then you need to use .closest(), which will select the closest parent element that matches the selector .navbar:
$(".navbar-toggler").click(function(){
$(this).closest('.navbar').toggleClass("is-clicked");
});
See a proof-of-concept example:
$(".navbar-toggler").click(function() {
$(this).closest('.navbar').toggleClass("is-clicked");
});
.navbar {
position: relative;
z-index: 98;
border-bottom: 4px solid #000000;
margin-left: 40px;
margin-right: 40px;
color: #000000;
height: 100px;
}
.navbar.is-clicked {
border-bottom-color: red;
}
.navbar-toggler {
font-size: 32px;
color: black;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar navbar-expand-lg">
<div class="container-fluid nav-container">
<a class="navbar-brand" href="index.html">ABC.</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="toggler-icon"><i class="fas fa-bars"></i>
</span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item nav-item-about p-nav">
<a class="nav-link" aria-current="page" href="about.html">About</a>
</li>
<li class="nav-item p-nav">
<a class="nav-contact" href="mailto:michellelclement#gmail.com?subject=Hello from your portfolio!">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

The Jquery:
$('.navbar-toggler').on('click', function(){
$('.navbar').toggleClass('is-clicked');
});
You also need to change this in your css:
.navbar.is-clicked {
border-bottom-color: red;
}

Related

navbar Toggle in bootstrap is not working

I am trying to work on twitter bootstrap to make a responsive website although i am facing some problem with the navigation toggle button I have included all the libraries which was the issue for some of the questions asked here still I am unable to know the exact problem.
body {
font-family: Arial, serif;
background: url(https://freenaturestock.s3.us-east-1.amazonaws.com/1602.jpg) center center no-repeat;
background-attachment: fixed;
background-size: cover;
}
/* editing the logo part*/
.logo {
height: 32px;
opacity: 1;
}
/* editing the navbar background colour*/
.navbar-inverse {
background: rgba(0, 0, 0, 0.5);
}
/* navbar list options editing*/
.nav li {
color: #fff;
font-size: 17px;
margin-right: 15px;
padding: 10px 15px;
}
.nav li:hover {
border-bottom: 3px solid #00FFB8;
padding-bottom: 3px;
}
<!DOCTYPE html>
<html lang="en">
<head>
< meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WebServ</title>
<link href="https://fonts.googleapis.com/css2?family=Arvo:ital,wght#0,400;0,700;1,400&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js" integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="styling.css">
</head>
<body data-spy="scroll" data-target=".navbar" data-offset="30">
<!-- Create a nav bar-->
<div class="container-fluid">
<nav role="navigation" class="navbar nav-tabs navbar-inverse bg-inverse navbar-toggleable navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar" aria-controls="myNavbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="sr-only">Toggle navigation</span>
<!-- <span class="navbar-toggler-icon"></span>-->
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logo</a>
</div>
<div class=" collapse navbar-collapse" id="myNavbar ">
<ul class=" nav navbar-nav navbar-right mylist">
<li class="nav-item" role="presentation"><a class="nav-link" href="#home"><span class="glyphicon glyphicon-home" style="padding: 8px;"></span>Home</a></li>
<li class="nav-item" role="presentation" " ><a class="nav-link " href="#about "><span class="glyphicon glyphicon-user " style="padding: 8px " ;></span>About</a>
</li>
<li class="nav-item " role="presentation "><a class="nav-link " href="#portfolio "><span class="glyphicon glyphicon-list-alt " style="padding: 8px; "></span>Portfolio</a></li>
<li class="nav-item " href="#role=" presentation "><a class="nav-link " href="#contact "><span class="glyphicon glyphicon-earphone " style="padding: 8px; "></span>Contact</a></li>
</ul>
</div>
</div>
</nav>
</div>
</body>
</html>
https://codepen.io/webserv01/pen/rNxKVrN
you had two problems, the first in id of navbar, you include a space:
id="myNavbar ">
Must be : id="myNavbar">
the second problem was you include old jquery release(with a bug, and two time?)
body {
font-family: Arial, serif;
background: url(https://freenaturestock.s3.us-east-1.amazonaws.com/1602.jpg) center center no-repeat;
background-attachment: fixed;
background-size: cover;
}
/* editing the logo part*/
.logo {
height: 32px;
opacity: 1;
}
/* editing the navbar background colour*/
.navbar-inverse {
background: rgba(0, 0, 0, 0.5);
}
/* navbar list options editing*/
.nav li {
color: #fff;
font-size: 17px;
margin-right: 15px;
padding: 10px 15px;
}
.nav li:hover {
border-bottom: 3px solid #00FFB8;
padding-bottom: 3px;
}
<link href="https://fonts.googleapis.com/css2?family=Arvo:ital,wght#0,400;0,700;1,400&display=swap" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<body data-spy="scroll" data-target=".navbar" data-offset="30">
<!-- Create a nav bar-->
<div class="container-fluid">
<nav role="navigation" class="navbar nav-tabs navbar-inverse bg-inverse navbar-toggleable navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar" aria-controls="myNavbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="sr-only">Toggle navigation</span>
<!-- <span class="navbar-toggler-icon"></span>-->
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logo</a>
</div>
<div class=" collapse navbar-collapse" id="myNavbar">
<ul class=" nav navbar-nav navbar-right mylist">
<li class="nav-item" role="presentation"><a class="nav-link" href="#home"><span class="glyphicon glyphicon-home" style="padding: 8px;"></span>Home</a></li>
<li class="nav-item" role="presentation" " ><a class="nav-link " href="#about "><span class="glyphicon glyphicon-user " style="padding: 8px " ;></span>About</a>
</li>
<li class="nav-item " role="presentation "><a class="nav-link " href="#portfolio "><span class="glyphicon glyphicon-list-alt " style="padding: 8px; "></span>Portfolio</a></li>
<li class="nav-item " href="#role=" presentation "><a class="nav-link " href="#contact "><span class="glyphicon glyphicon-earphone " style="padding: 8px; "></span>Contact</a></li>
</ul>
</div>
</div>
</nav>
</div>
</body>

Alignment issue with Bootstrap Nav & Flexbox Items at either end

I'm having difficulty moving items on my Navbar to either end. At the moment I have this:
I would like to move the flag image next to the toggler button, it is only there when the breakpoint reaches the Navbar button size, 992px.
I'm sure the Bootstrap Stylesheet is aligning it using justify-content: space-between; I have tried using align-self: flex-end !important; on both flag and button as well as using justify-content-end
Codepen - https://codepen.io/jvern22/pen/gZjJBN
My Nav code;
<div class="container container-navbar">
<a class="navbar-brand" href="index.php">Website title</a>
<a class="navbar-brand justify-content-end" href="#"><img src="assets/img/spain.png" class="navbar-flag"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#top-navbar-1" aria-controls="top-navbar-1" aria-expanded="true" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="top-navbar-1">
<ul class="navbar-nav justify-content-end">
<li class="nav-item"><a class="nav-link" href="?page=taketour"><?php echo $lang['nav_takeatour']; ?></a></li>
<li class="nav-item"><a class="nav-link" href="?page=websites"><?php echo $lang['nav_websites']; ?></a></li>
</ul>
</div>
</div>
</nav>
You can either wrap the flag and the navbar button within a div as shown in this CodePen or in the Code Snippet below:
html {
height:100%;
box-sizing: border-box;
}
body {
min-height:100%;
padding:0;
margin:0;
position:relative;
font: 400 15px "Open Sans", sans-serif;
line-height: 30px;
text-align: center;
overflow-x: hidden;
-webkit-font-smoothing: antialiased;
}
.bg-dark {
background: #000 !important;
color: #fff;
}
.bg-dark a {
color: #aaa;
}
.bg-dark a:hover, .bg-dark a:focus {
color: #fff;
}
.navbar-nav>li>a {
line-height: 20px;
padding-right: 12px!important;
padding-left: 12px!important;
padding-top: 10px!important;
padding-bottom: 10px!important;
}
.navbar-flag {
height: 20px;
}
#media (min-width: 992px) and (max-width: 2200px){
.navbar-flag {
display: none;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-dark navbar-no-bg" role="navigation">
<div class="container container-navbar">
<a class="navbar-brand" href="index.php">Website title</a>
<div>
<a class="navbar-brand justify-content-end" href="#"><img src="
https://i.imgur.com/TXhhmGb.png" class="navbar-flag"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#top-navbar-1" aria-controls="top-navbar-1" aria-expanded="true" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="top-navbar-1">
<ul class="navbar-nav justify-content-end">
<li class="nav-item"><a class="nav-link" href="?page=taketour"><?php echo $lang['nav_takeatour']; ?></a></li>
<li class="nav-item"><a class="nav-link" href="?page=websites"><?php echo $lang['nav_websites']; ?></a></li>
<li class="nav-item"><a class="nav-link" href="?page=rates"><?php echo $lang['nav_rates']; ?></a></li>
<li class="nav-item"><a class="nav-link" href="?page=contactus"><?php echo $lang['nav_contact']; ?></a></li>
</ul>
</div>
</div>
</nav>
Or you can just change the justify-content property of the parent div from space-between to flex-end and add a margin-right: auto to the first navbar-brand as shown in this CodePen or in the Code Snippet below:
html {
height:100%;
box-sizing: border-box;
}
body {
min-height:100%;
padding:0;
margin:0;
position:relative;
font: 400 15px "Open Sans", sans-serif;
line-height: 30px;
text-align: center;
overflow-x: hidden;
-webkit-font-smoothing: antialiased;
}
a.navbar-brand:first-child {
margin-right: auto;
}
.bg-dark {
background: #000 !important;
color: #fff;
}
.bg-dark a {
color: #aaa;
}
.bg-dark a:hover, .bg-dark a:focus {
color: #fff;
}
.navbar-nav>li>a {
line-height: 20px;
padding-right: 12px!important;
padding-left: 12px!important;
padding-top: 10px!important;
padding-bottom: 10px!important;
}
.navbar-flag {
height: 20px;
}
#media (min-width: 992px) and (max-width: 2200px){
.navbar-flag {
display: none;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-dark navbar-no-bg" role="navigation">
<div class="container container-navbar">
<a class="navbar-brand" href="index.php">Website title</a>
<a class="navbar-brand justify-content-end" href="#"><img src="
https://i.imgur.com/TXhhmGb.png" class="navbar-flag"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#top-navbar-1" aria-controls="top-navbar-1" aria-expanded="true" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="top-navbar-1">
<ul class="navbar-nav justify-content-end">
<li class="nav-item"><a class="nav-link" href="?page=taketour"><?php echo $lang['nav_takeatour']; ?></a></li>
<li class="nav-item"><a class="nav-link" href="?page=websites"><?php echo $lang['nav_websites']; ?></a></li>
<li class="nav-item"><a class="nav-link" href="?page=rates"><?php echo $lang['nav_rates']; ?></a></li>
<li class="nav-item"><a class="nav-link" href="?page=contactus"><?php echo $lang['nav_contact']; ?></a></li>
</ul>
</div>
</div>
</nav>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
The easiest solution here is to just expand the first flex item so that it pushes all the other items to the right. This can be easily done by adding the following to your css:
.navbar-brand:first {
flex-grow: 1;
}

bootstrap - Why does my navbar not appear on the next line?

I am trying to create a responsive website: when resizing the window, you get the "mobile" view. So a button appears. By pushing on the button you can toggle the navigation bar (make it appear and disappear).
This website does this very well: https://blackrockdigital.github.io/startbootstrap-freelancer/
So I tried replicating this behaviour myself:
<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/test.css">
</head>
<body>
<!--Navigation bar-->
<nav class="navbar navbar-custom navbar-fixed-top" id="myNavbar">
<div class="container">
<div class="navbar-brand">
<img src="images/testLogo.png">
</div>
<button class="navbar-toggler navbar-toggler-right text-uppercase bg-primary text-white rounded" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbarResponsive" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right" id="ul">
<li class="active">Home</li>
<li>Services</li>
<li>Partners</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
</body>
</html>
CSS:
/**
* Navigation bar.
*/
#myNavbar
{
padding-top: 1.5rem;
padding-bottom: 2.5rem;
background-color: rgb(100, 100, 100);
}
#navbarResponsive
{
width: 65%;
}
.navbar-collapse
{
flex-basis: 100%;
flex-grow: 1;
}
.nav > li > a
{
font-size: 18px
}
.navbar-brand
{
font-size: 28px;
}
img
{
height: 70px;
width: 70px;
float: right;
margin-top:-20px;
margin-left: 20px;
}
.navbar > .container, .navbar > .container-fluid
{
display: flex;
justify-content: space-between;
}
#media (min-width: 900px)
{
.navbar-toggler
{
display:none;
}
}
.container
{
width: 100%;
}
button
{
background-color: transparent;
}
.bg-primary
{
background-color: transparent;
}
.navbar-toggler-icon
{
background-color: transparent;
display: inline-block;
width: 1.5em;
height: 1.5em;
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(0, 0, 0, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E");
}
Everything seems ok, but when pushing the button the navigation bar (Home - Services - Partners - Contact) does not appear on the next line but rather on the same line and everything gets shifted to the left: https://imgur.com/a/8JU2oKT
Could someone tell me why the navigation bar is not displayed on the next line?
From a quick glance at your code the css seems not to be the problem, rather the placement of your div's. Try to replace the HTML to this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/test.css">
</head>
<body>
<!--Navigation bar-->
<nav class="navbar navbar-custom navbar-fixed-top" id="myNavbar">
<div class="container">
<div class="navbar-brand">
<img src="images/testLogo.png">
</div>
<button class="navbar-toggler navbar-toggler-right text-uppercase bg-primary text-white rounded" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div id="navbarResponsive" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right" id="ul">
<li class="active">Home</li>
<li>Services</li>
<li>Partners</li>
<li>Contact</li>
</ul>
</div>
</nav>
</body>
</html>
I replaced the div with the actual menu inside, outside of the container div but still inside the nav.
Try this code;
HTML
<!-- .navbar -->
<nav class="navbar navbar-full navbar-dark bg-primary">
<button class="navbar-toggler hidden-lg-up" type="button" data-toggle="collapse" data-target="#mainNavbarCollapse">
☰
</button>
<a class="navbar-brand" href="#">
<img class="img-rounded" src="images/testLogo.png">
</a>
<div class="collapse navbar-toggleable-md" id="mainNavbarCollapse">
<ul class="nav navbar-nav pull-lg-right">
<li class="nav-item">
<a class="nav-link" href="main.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="services.html">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="projects.html">Partners</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact.html">Contact</a>
</li>
</ul>
</div>
</nav>
<!-- /.navbar -->
CSS
#media (max-width: 62em) {
.navbar-nav {
padding-top: .425rem;
padding-left: 0.75rem;
}
.navbar-nav .nav-item {
float: none;
}
.navbar-brand {
float: right;
}
.navbar-brand,
.navbar-nav .nav-item {
display: block;
}
.navbar-nav .nav-item + .nav-item {
margin-left: 0;
}
.dropdown-menu {
position: relative;
float: none;
}
}

How to center vertically menu items on nav bar?

I try to center vertically menu items "TEST 1","TEST 2" and "BRAND" without successful.
I have tried vertical-align,margin-top and bottom.
I mean, I don't want to put one on top of another, just center between margin top and bottom of the nav bar.
I really appreciate if somebody can help me.
HTML
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-
toggle="collapse" data-target="#menu-collapse" 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>
BRAND
</div>
<div class="collapse navbar-collapse" id="menu-collapse">
<ul class="nav navbar-nav navbar-center">
<li><a id="menu-right" href="#">TEST 1</a></li>
<li><a id="menu-right" href="#">TEST 2</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><button class="btn btn-primary">Start Now</button></li>
<li><button class="btn btn-primary">Member Login </button>
</li>
</ul>
</div>
</div>
</nav>
CSS
#menu-right:hover {
background: #5d5dc9;
color:#fff;
}
#menu-right {
color:#337ab7;
text-transform: uppercase;
vertical-align: middle;
}
ul {
vertical-align: middle;
}
.button-margin {
border: 1px solid;
}
.navbar-brand {
margin-right: 200px;
}
.navbar {
margin-bottom: 0;
font-family: 'Raleway', sans-serif;
font-size: 1.5em;
font-weight: 800;
text-transform: uppercase;
}
Here is a link to codepen website test : https://codepen.io/fdcoder81/pen/Kymyyj
Thank you very much
If you set the line-height of your a tags to the height of the navbar it should be aligned vertically centered.
Btw both of your:
<a id="menu-right" href="#">
occurences should have classes - you can't have the same id assigned more than one element.
Take
<a class="menu-right" href="#">
And change in your css accordingly to
.menu-right
EDIT:
I played around with your codepen stuff - I don't know if that's the way to go when using bootstrap but it works.
Your HTML:
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TEST</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,900" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Raleway:400,800" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<header>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#menu-collapse" 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>
BRAND
</div>
<div class="collapse navbar-collapse" id="menu-collapse">
<ul class="nav navbar-nav navbar-center">
<li>
<a class="menu-right" href="#">TEST 1</a>
</li>
<li>
<a class="menu-right" href="#">TEST 2</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="#">
<button class="btn btn-primary">Start Now</button>
</a>
</li>
<li>
<a href="#">
<button class="btn btn-primary">Member Login </button>
</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!--<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>-->
</body>
</html>
Your CSS:
.menu-right:hover {
background: #5d5dc9;
color: white;
}
.menu-right {
color:#337ab7;
text-transform: uppercase;
line-height: 54px;
}
.button-margin {
border: 1px solid;
}
.navbar > .container-fluid .navbar-brand {
margin-right: 200px;
line-height: 54px;
padding-top: 0;
padding-bottom: 0;
}
.navbar {
margin-bottom: 0;
font-family: 'Raleway', sans-serif;
font-size: 1.5em;
font-weight: 800;
text-transform: uppercase;
}
.navbar-default .navbar-nav>li>a {
line-height: 54px;
padding-top: 0;
padding-bottom: 0;
}

Too much space between list items in Navbar Bootstrap

How do I make it so the items (menu, about us, etc) are all evenly spaced out throughout the navbar and not bunched up to one side?
https://jsfiddle.net/dd19sg5x/
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<nav class="navbar navbar-default">
<div>
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-nav-demo" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar">a</span>
<span class="icon-bar">b</span>
<span class="icon-bar">c</span>
</button>
<img src="images\logo.png" href="main_page.html" width=75% height=75% alt="Company Logo of Broadstairs Hotel" href="www.google.com"/>
</div>
<div class="collapse navbar-collapse container" id="bs-nav-demo">
<ul class="nav navbar-nav" id="top-navbar">
<li>Book</li>
<li>Menu</li>
<li>Enquire</li>
<li>Facillities</li>
<li>Rooms</li>
<li>Contact us</li>
<!-- Navbar stuff is done -->
</div>
</div>
</nav>
My tip is to set the .navbar-header to a fixed width depending on your logo width and make it position: absolute;. I've set it to 200px;. Than the padding-left of the .navbar-collapse will be that 200px; After that if you have 6 menuitems, than one item should be exactly 16.666% wide.
See it in action here: https://jsfiddle.net/9ts0Lcxe/
Added code in css in is:
#media (min-width: 768px) {
.navbar .navbar-header {
position: absolute;
left: 0;
top: 0;
width: 200px;
}
.navbar .navbar-collapse {
width: 100%;
padding-left: 200px;
}
.navbar .navbar-collapse .navbar-nav {
width: 100%;
}
.navbar .navbar-collapse .navbar-nav > li {
width: 16.666%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
CSS Flex seems to be a good solution.
These two links have helped me a lot.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Your code could look like this:
#media (min-width: 992px) {
ul.navbar-nav {
display: flex;
justify-content: space-between;
width: 100%
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="nav-brand"><img src="images\logo.png" href="main_page.html" width=75% height=75% alt="Company Logo of Broadstairs Hotel" href="www.google.com"/></a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="html\book.html">Book</a></li>
<li class="nav-item"><a class="nav-link" href="#">Menu</a></li>
<li class="nav-item"><a class="nav-link" href="#">Enquire</a></li>
<li class="nav-item"><a class="nav-link" href="#">Facillities</a></li>
<li class="nav-item"><a class="nav-link" href="#">Rooms</a></li>
<li class="nav-item"><a class="nav-link" href="#">Contact us</a></li>
</ul>
</div>
</nav>