I'm a new to this website and for coding, i m trying to highlight active menu. i have been search almost of two weeks. still not resolved. i have tried with jquery cdn, it works, but when i upload all this to web, it doesn't work. when i click the menu it highlight and disappear suddenly. so it didnt succes with jquery cdn. here is the jquery cdn i have used.
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript">
$(document).on('click', 'ul li', function(){
$(this).addClass('active').siblings().removeClass('active')
})
</script>
please help. here are my codes. if css wrong can someone of you please correct this?
<div id="main-wrap">
<nav class="navbar navbar-default ">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/">
<div class="sidebar-pinner">
<button type="button" class="btn btn-secondary 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>
</div>
</div>
<div id="scrollNav">
<ul class="nav navbar-nav navbar-left-block">
<li><span class="ico"><i class="fas fa-home"></i></span> Home</li>
<li class="currentPage"><a>Home</a></li>
</ul>
<ul class="nav navbar-nav navbar-right navbar-right-block">
<li class="user-balance"><span class="ico"><i class="material-icons">attach_money</i></span> <span class="nav-text">$0.00</span><span class="hidden badge" style="background-color: #fea621;">$0.00</span></li>
<li class="dropdown">
<span class="ico"><i class="fas fa-user-cog"></i></span> <span class="nav-text">newuserpanel</span> <span class="caret"></span>
<ul class="dropdown-menu">
<li>Account</li>
<li>API</li>
<li>Logout</li>
</ul>
</li>
</ul>
</div>
<div class="collapse navbar-collapse mobileNav" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li ><span class="ico"><img src="/home.png" alt="Home" /></span> Home</li>
<li ><span class="ico"><img src="/Services.png" alt="Services" /></span> Services</li>
<li ><span class="ico"><img src="/history.png" alt="History" /></span> history</li>
<li ><span class="ico"><img src="/Support.png" alt="Support" /></span> Support</li>
<li ><span class="ico"><img src="/FAQ.png" alt="FAQ" /></span> FAQ</li>
<li ><span class="ico"><img src="/API.png" alt="API" /></span> API</li>
<li ><span class="ico"><img src="/Terms.png" alt="Terms" /></span> Terms</li>
</ul>
</div>
</div>
</nav>
<div class="nav-bottom">
<div class="container">
<ul class="nav page-navigation">
<li ><span class="ico"><img src="home.png" alt="Home" /></span> Home</li>
<li ><span class="ico"><img src="Services.png" alt="Services" /></span> Services</li>
<li ><span class="ico"><img src="history.png" alt="Orders" /></span> History</li>
<li ><span class="ico"><img src="/API.png" alt="API" /></span> API</li>
<li class="dropdown ">
<span class="ico"><img src="/dggher5t.png" alt="chaman" /></span> Support <span class="caret"></span>
<ul class="dropdown-menu">
<li ><span class="ico"><img src="/Support.png"/></span> Support</li>
<li ><span class="ico"><img src="/FAQ.png" alt="FAQ" /></span> FAQ</li>
<li ><span class="ico"><img src="/Terms.png" alt="Terms" /></span> Terms</li>
</ul>
</li>
</ul>
</div>
</div>
here is the css
}
.dahshat-board .navbar-default {
background-color: transparent;
border-color: transparent;
padding: 10px 0;
margin: 0;
background-image: none;
}
.nav-bottom {
position: relative;
z-index: 3;
}
.nav.page-navigation {
background: #fad534;
border-radius: 500px;
display: flex;
width: 100%;
position: relative;
box-shadow: 0 2px 10px 0 rgba(0,0,0,.08);
justify-content: center;
}
.nav.page-navigation li {
display: inline-flex;
width: auto;
align-items: center;
flex: 0 0 10.85%;
flex-grow: 1;
}
.nav-bottom .nav .dropdown li {
display: block;
width: auto;
text-align: left;
}
.nav-bottom .nav li .ico {
margin-right: 4px;
width: 28px;
height: 28px;
background: #2b1f60;
border-color: #2b1f60;
}
.nav-bottom .nav li.active .ico {
background: #fad534;
border-color: #fad534;
}
.nav-bottom .nav li.active .ico img {
filter: invert(1) brightness(100%) saturate(0);
}
.nav-bottom .nav li a {
font-size: 13px;
line-height: 44px;
color: #2a1e5e;
display: flex;
justify-content: center;
position: relative;
align-items: center;
padding: 2px 9px;
border-radius: 500px;
white-space: pre;
width:100%;
}
.nav-bottom .nav li.dropdown.open a.dropdown-toggle {
/* background: transparent;
border: none; */
}
.nav-bottom .nav li a:hover,
.nav-bottom .nav li a:active,
.nav-bottom .nav li a:focus {
background: transparent;
outline: none;
}
.nav-bottom .nav .dropdown li a {
line-height: 18px;
display: block;
padding: 4px 10px;
position: relative;
}
.nav-bottom .nav .dropdown li a .badge {
position: absolute;
right: 8px;
top: 13px;
padding: 3px 7px;
font-size: 10px;
}
.nav-bottom .nav li.active a {
color: #fad534;
background-color: #270044;
}
.nav-bottom .nav .dropdown li a::after,
.nav-bottom .nav .dropdown li a::before {
display: none;
}
.navbar-collapse.mobileNav{
padding:0;
}
.navbar-collapse.collapse.mobileNav ul.navbar-nav.nav {
display: none;
}
.nav-bottom .nav li.dropdown.open .dropdown-menu a {
background: transparent;
border-radius: 0;
color: #2a1e5e;
}
.dahshat-board .navbar-default .navbar-nav > li > a {
color: #ffffff;
font-size: 14px;
padding-top: 0;
padding-bottom: 0;
display: flex;
align-items: center;
padding-top: 10px;
padding-bottom: 10px;
line-height: 34px;
}
.dahshat-board .navbar-default #scrollNav.fixedNav .navbar-nav > li > a {
color: #4d0e88;
}
.dahshat-board .navbar-default #scrollNav.fixedNav .navbar-nav > li > a .ico {
background: #480d80;
color: #efe9f5;
border: 1px solid #480d80;
}
.dahshat-board .navbar-default .navbar-nav > li > a:hover,
.dahshat-board .navbar-default .navbar-nav > li > a:focus{
color: #ffffff;
background-color:transparent;
}
.dahshat-board .navbar-default .navbar-nav > .open > a,
.dahshat-board .navbar-default .navbar-nav > .open > a:hover,
.dahshat-board .navbar-default .navbar-nav > .open > a:focus{
background: transparent;
}
.dahshat-board .navbar-default .navbar-nav.navbar-left-block .currentPage {
position: relative;
}
.dahshat-board .navbar-default .navbar-nav.navbar-left-block .currentPage::before {
content: '/';
color: #ffffff;
display: inline-block;
position: absolute;
top: 17px;
left: 0;
}
.dahshat-board .navbar-default #scrollNav.fixedNav .navbar-nav.navbar-left-block .currentPage::before{
color: #480d80;
}
.navbar-nav li.mobileSearch{
display: none;
}
The previous CSS it's a little too long, so i'll get into the explanation.
When you use this
$(document).on('click', 'ul li', ...
You're selectin any li element which is son, or grandson or so on, from any ul element. This kind of selector should be used wisely, or you may end selecting something you don't want to.
So first, try changing that into
$(document).on('click', 'ul>li', ...
To select only li elements who are direct child of ul elements.
Then, make sure that your CSS rules target to li elements with an "active" class to apply your rule and that should make it.
Edit: If this is the only thing where you're using Jquery, you may try this instead and get rid of Jquery in order to save some bandwidth when loading the page:
let prev = null;
let items = document.querySelectorAll("ul>li");
items.forEach((el)=> el.addEventListener("click", ()=>{
el.classList.add("active");
if(prev) prev.classList.remove("active");
prev = el;
});
I hope this helps enough.
Related
I want to change the background color of the active nav-item and of any nav-item hovered to "chartreuse" (just a color to test).
I've tried love of things but it's not working, why?
Not even using !important.
https://codepen.io/ogonzales/pen/abNQXLg
CSS:
/* NAVBAR TOP */
#top-navbar {
background-color: #1f1f1f;
}
.navbar-nav > .active > a {
color: aqua;
background-color: chartreuse;
}
.nav-item > a:hover {
color: aqua;
}
#navbarCollapse {
margin-left: 1%;
}
#navbarCollapse ul li {
display: inline-block;
}
.nav-link {
margin: 5px;
width: 100px;
}
/* start update */
nav ul {
margin-bottom: 0;
}
.navbar-light .navbar-toggler-icon {
background-image: none;
font-size: 25px;
height: auto;
width: auto;
padding: 3px;
}
#navbarCollapse ul {
padding-top: 10px
}
#navbarCollapse ul li a {
margin: 0;
padding: 5px 10px;
}
nav {
position: relative
}
nav form {
position: absolute;
top: 7px;
right: 15px;
}
Target the active nav-item like this:
.nav-item.active > a{
}
Then you can add css styling into it.
Before you weren't selecting the element properly.
What you desired:
.nav-item.active > a {
color: aqua;
}
.nav-item > a:hover {
background-color: chartreuse;
}
See codepen: https://codepen.io/koder613/pen/ZEWNEgw?editors=1100
To change the background color of the active nav-item. Call the navbar-nav class as it is in your ul tag as shown.
<div class="collapse navbar" id="navbarCollapse">
<!-- Call the navbar-nav class in the ul tag -->
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/">Inicio</a>
</li>
<li class="nav-item">
<a href="/iglesias/" class="nav-link" >Iglesias</a>
</li>
<li class="nav-item">
<a href="/doctrina/" class="nav-link" >Doctrina</a>
</li>
</ul>
</div>
And the following will show the "chartreuse" color when you hover over the nav-items.
.nav-item > a:hover { color: aqua; background-color: chartreuse; }
I added active class on your second li to show how it looks like.
But more or less you should set your changing color in active class like:
.active{
background-color: red;
}
.active:hover > a{
color: yellow !important;
}
Like this both color will change when mouse is going hover your li with active class. And You add important where you want to make it stronger.
Pretty much duplicate of: Changing the color of active nav-item
$(document).ready(function() {
"use strict";
$('ul > li').click(function(e) {
e.preventDefault();
$('ul > li').removeClass('active');
$(this).addClass('active');
});
});
/* NAVBAR TOP */
#top-navbar {
background-color: #1f1f1f;
}
.navbar-nav > .active > a {
color: aqua;
background-color: chartreuse;
}
.active{
background-color: red;
}
.nav-item.active:hover > a{
color: yellow !important;
}
.nav-item > a:hover {
color: aqua;
}
#navbarCollapse {
margin-left: 1%;
}
#navbarCollapse ul li {
display: inline-block;
}
.nav-link {
margin: 5px;
width: 100px;
}
/* start update */
nav ul {
margin-bottom: 0;
}
.navbar-light .navbar-toggler-icon {
background-image: none;
font-size: 25px;
height: auto;
width: auto;
padding: 3px;
}
#navbarCollapse ul {
padding-top: 10px
}
#navbarCollapse ul li a {
margin: 0;
padding: 5px 10px;
}
nav {
position: relative
}
nav form {
position: absolute;
top: 7px;
right: 15px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header>
<!--MENU SUPERIOR-->
<!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-light fixed-top" id="top-navbar">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<!-- <span class="navbar-toggler-icon"><i class="fas fa-bars"></i></span> -->
<span class="navbar-toggler-icon">
<i class="fas fa-bars" style="color:#fff; font-size:28px;"></i>
</span>
</button>
<a class="navbar-brand mr-auto mt-0" href="/"><img src="/static/img/logos/elim-palmera-la-central-fondo-blanco.png" width="25px"
height="30px"></a>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul>
<li class="nav-item">
<a class="nav-link" href="/">Inicio</a>
</li>
<li class="nav-item active">
<a href="/iglesias/" class="nav-link" >Iglesias</a>
</li>
<li class="nav-item">
<a href="/doctrina/" class="nav-link" >Doctrina</a>
</li>
</ul>
</div>
<form class="form-inline ml-auto mt-3">
<span class="text-white">Hola, ogonzales.</span>
Salir
</form>
</div>
</nav>
</header>
So I have this code:
.hoverlist12:hover #details {
display: block;
}
The thing is the list doesn't appear at all. If I change the hoverlist12 class with the ul, it works fine, but it appears when I hover on all the elements, and I want it to appear when I hover it only on the first "li". Usually, I have no problem doing this but now I just can't figure it out.
.navbar {
border-radius: 0;
max-height: 50px;
}
.navbar-default .navbar-nav > li > a,
.navbar-default .navbar-brand {
color: #ffffff;
}
.navbar-default .navbar-brand:hover {
color: #ffffff;
transform: scale(1.1);
}
.navbar-default .navbar-nav > li > a:focus,
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-brand:focus,
.navbar-default .navbar-brand:hover {
color: #ffffff;
}
.navbar-default .navbar-nav > li:focus,
.navbar-default .navbar-nav > li:hover {
background-color: rgba(0, 0, 0, 0.15);
}
nav {
font-family: "ITCErasStd-Medium";
}
.hiddeOnTop {
visibility: hidden;
}
.container-fluid {
padding-right: 3%;
padding-left: 3%;
display: inline-block;
width: 100%;
}
.navbar-default,
.container-fluid {
background-color: #be3c7a;
}
.nav > li > a {
font-size: 1.1em;
}
.navbar .facebook {
padding: 0;
margin-top: 7px;
}
.navbar .facebook:hover {
background: none;
transform: scale(1.1);
}
.navbar-brand,
.nav > li.active > a {
font-family: "ITCErasStd-Bold";
}
#details {
padding: 26px 30px;
display: none;
color: white;
z-index: 900;
font-size: 2rem;
list-style-type: none;
position: absolute;
margin-top: 50px;
background-color: #be3c7a;
}
.hoverlist12:hover #details {
display: block;
}
<nav class="mobile_nav">
<button type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<ul class="nav-content">
<li>
<a href="htps://www.facebook.com" alt="facebook" class="facebook"
><img
src="./img/fb-icon.svg"
alt="fb-icon"
onerror="this.src='./img/fb-icon.png'"
/></a>
</li>
<!-- <li class="homelk">HOME</li> -->
<li class="homelk">
CE ESTE adadsadassssss
</li>
<li>INTREBARI FRECVENTE</li>
<li>PARTENERI</li>
<li>CONTACT</li>
<!-- <li><i class="fa fa-facebook-official"></i></li> -->
</ul>
</nav>
<!-- //////////////////////////// NAVBAR \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->
<nav class="navbar navbar-default">
<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 navigate" href="#home"><span>HOssME</span></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right dropdown">
<li class="hoverlist12">
CE ESTE USCACIUNEA
</li>
<ul id="details">
<li>Manifestari</li>
<li>Femeia activa</li>
<li>Maternitatea</li>
<li>Menopauza</li>
<li>Sub tratament</li>
</ul>
<li> DE CE HAYLO GYN </li>
<li> INTREBARI </li>
<li>CONTACT</li>
<li>
<a href="htps://www.facebook.com" alt="facebook" class="facebook"
><img
src="./img/fb-icon.svg"
alt="fb-icon"
s
onerror="this.src='./img/fb-icon.png'"
/></a>
</li>
<!-- <li><i class="fa fa-facebook-official"></i></li> -->
</ul>
</div>
</div>
</nav>
Use selector like this: .hoverlist12:hover ~ #details Because #details and .hoverlist12 elements are siblings or at same level. You can use this selector only .hoverlist12:hover #details when #details is a child element of .hoverlist12. So, please change your CSS code as I suggested OR Please change your structure like:
<li class="hoverlist12">
CE ESTE USCACIUNEA
<ul id="details">
<li>Manifestari</li>
<li>Femeia activa</li>
<li>Maternitatea</li>
<li>Menopauza</li>
<li>Sub tratament</li>
</ul>
</li>
I'm playing with this code now and trying to learn something in this, I have trying to align my <li></li> to collection in header menu but suddenly I failed a lot. Can someone explain me the solution on this?
jQuery(document).on('click', '.mega-dropdown', function(e) {
e.stopPropagation()
})
#import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
font-family: 'Open Sans', 'sans-serif';
background: #f4f4f4;
}
.navbar-default {
background-color: #c42027;
}
h1,
.h1 {
font-size: 36px;
text-align: center;
font-size: 5em;
}
.navbar-nav>li>.dropdown-menu {
margin-top: 20px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.navbar-default .navbar-nav>li>a {
width: 130px;
font-weight: bold;
color: #ffffff;
}
.mega-dropdown {
position: static !important;
width: 100%;
}
.mega-dropdown-menu {
padding: 20px 0px;
width: 100%;
box-shadow: none;
-webkit-box-shadow: none;
}
.mega-dropdown-menu:before {
content: "";
border-bottom: 15px solid #fff;
border-right: 17px solid transparent;
border-left: 17px solid transparent;
position: absolute;
top: -15px;
left: 285px;
z-index: 10;
}
.mega-dropdown-menu:after {
content: "";
border-bottom: 17px solid #ccc;
border-right: 19px solid transparent;
border-left: 19px solid transparent;
position: absolute;
top: -17px;
left: 283px;
z-index: 8;
}
.mega-dropdown-menu > li > ul {
padding: 0;
margin: 0;
}
.mega-dropdown-menu > li > ul > li {
list-style: none;
color: #222;
}
.mega-dropdown-menu > li > ul > li > a {
display: inline;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.428571429;
color: #000000;
white-space: normal;
}
.mega-dropdown-menu > li ul > li > a:hover,
.mega-dropdown-menu > li ul > li > a:focus {
text-decoration: none;
color: #ff3546;
background-color: #f5f5f5;
}
.mega-dropdown-menu .dropdown-header {
color: #ff3546;
font-size: 18px;
font-weight: bold;
}
.navbar-inverse .navbar-nav>li>a {
color: white;
background-color: #ffffff;
margin: 0;
padding: 0 15px;
line-height: 50px;
display: block;
}
.navbar-default .navbar-nav>li>a:hover {
color: black;
background-color: white;
}
.navbar-default .navbar-nav>.open>a:hover {
color: black;
background-color: white;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<nav class="navbar navbar-default">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".js-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 src="images/logo/conlins logo.jpg">
</a>
</div>
<div class="collapse navbar-collapse js-navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
Collection <span class="glyphicon glyphicon-chevron-down pull-right"></span>
<ul class="dropdown-menu mega-dropdown-menu row">
<li class="col-sm-4">
<ul>
<li class="dropdown-header">Dresses</li>
<li>Unique Features</li>
<li>Image Responsive</li>
<li>Auto Carousel</li>
<li>Newsletter Form</li>
<li>Four columns</li>
<li class="divider"></li>
<li class="dropdown-header">Tops</li>
<li>Good Typography</li>
</ul>
</li>
<li class="col-sm-4">
<ul>
<li class="dropdown-header">Jackets</li>
<li>Easy to customize</li>
<li>Glyphicons</li>
<li>Pull Right Elements</li>
<li class="divider"></li>
<li class="dropdown-header">Pants</li>
<li>Coloured Headers</li>
<li>Primary Buttons & Default</li>
<li>Calls to action</li>
</ul>
</li>
<li class="col-sm-4">
<ul>
<li class="dropdown-header">Accessories</li>
<li>Default Navbar</li>
<li>Lovely Fonts</li>
<li>Responsive Dropdown </li>
<li class="divider"></li>
<li class="dropdown-header">Newsletter</li>
</ul>
</li>
</ul>
<li>Events</li>
<li>Store</li>
<li>About us</li>
<li>Contact us</li>
<li>Career</li>
<li>
<div class="social_media">
<a href="https://www.facebook.com/conlinscoffee/">
<img src="images/social_media/facebook.png" height="20px" width="auto"> </a>
<a href="https://twitter.com/hashtag/conlinscoffee">
<img src="images/social_media/twitter.png" height="20px" width="auto"> </a>
<a href="#">
<img src="images/social_media/instagram.png" height="20px" width="auto">
</a>
</div>
</li>
</ul>
</div>
<!-- /.nav-collapse -->
</nav>
</div>
If I am right, the class mega-dropdown is what is making it take full width. So if you take away that class, it works. Or just remove the width: 100%.
jQuery(document).on('click', '.mega-dropdown', function(e) {
e.stopPropagation()
})
#import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
font-family: 'Open Sans', 'sans-serif';
background: #f4f4f4;
}
.navbar-default {
background-color: #c42027;
}
h1,
.h1 {
font-size: 36px;
text-align: center;
font-size: 5em;
}
.navbar-nav>li>.dropdown-menu {
margin-top: 20px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.navbar-default .navbar-nav>li>a {
width: 130px;
font-weight: bold;
color: #ffffff;
}
.mega-dropdown {
position: static !important;
/* width: 100%; */
}
.mega-dropdown-menu {
padding: 20px 0px;
width: 100%;
box-shadow: none;
-webkit-box-shadow: none;
}
.mega-dropdown-menu:before {
content: "";
border-bottom: 15px solid #fff;
border-right: 17px solid transparent;
border-left: 17px solid transparent;
position: absolute;
top: -15px;
left: 285px;
z-index: 10;
}
.mega-dropdown-menu:after {
content: "";
border-bottom: 17px solid #ccc;
border-right: 19px solid transparent;
border-left: 19px solid transparent;
position: absolute;
top: -17px;
left: 283px;
z-index: 8;
}
.mega-dropdown-menu > li > ul {
padding: 0;
margin: 0;
}
.mega-dropdown-menu > li > ul > li {
list-style: none;
color: #222;
}
.mega-dropdown-menu > li > ul > li > a {
display: inline;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.428571429;
color: #000000;
white-space: normal;
}
.mega-dropdown-menu > li ul > li > a:hover,
.mega-dropdown-menu > li ul > li > a:focus {
text-decoration: none;
color: #ff3546;
background-color: #f5f5f5;
}
.mega-dropdown-menu .dropdown-header {
color: #ff3546;
font-size: 18px;
font-weight: bold;
}
.navbar-inverse .navbar-nav>li>a {
color: white;
background-color: #ffffff;
margin: 0;
padding: 0 15px;
line-height: 50px;
display: block;
}
.navbar-default .navbar-nav>li>a:hover {
color: black;
background-color: white;
}
.navbar-default .navbar-nav>.open>a:hover {
color: black;
background-color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<nav class="navbar navbar-default">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".js-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 src="images/logo/conlins logo.jpg">
</a>
</div>
<div class="collapse navbar-collapse js-navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
Collection <span class="glyphicon glyphicon-chevron-down pull-right"></span>
<ul class="dropdown-menu row">
<li class="col-sm-4">
<ul>
<li class="dropdown-header">Dresses</li>
<li>Unique Features</li>
<li>Image Responsive</li>
<li>Auto Carousel</li>
<li>Newsletter Form</li>
<li>Four columns</li>
<li class="divider"></li>
<li class="dropdown-header">Tops</li>
<li>Good Typography</li>
</ul>
</li>
<li class="col-sm-4">
<ul>
<li class="dropdown-header">Jackets</li>
<li>Easy to customize</li>
<li>Glyphicons</li>
<li>Pull Right Elements</li>
<li class="divider"></li>
<li class="dropdown-header">Pants</li>
<li>Coloured Headers</li>
<li>Primary Buttons & Default</li>
<li>Calls to action</li>
</ul>
</li>
<li class="col-sm-4">
<ul>
<li class="dropdown-header">Accessories</li>
<li>Default Navbar</li>
<li>Lovely Fonts</li>
<li>Responsive Dropdown </li>
<li class="divider"></li>
<li class="dropdown-header">Newsletter</li>
</ul>
</li>
</ul>
<li>Events</li>
<li>Store</li>
<li>About us</li>
<li>Contact us</li>
<li>Career</li>
<li>
<div class="social_media">
<a href="https://www.facebook.com/conlinscoffee/">
<img src="images/social_media/facebook.png" height="20px" width="auto"> </a>
<a href="https://twitter.com/hashtag/conlinscoffee">
<img src="images/social_media/twitter.png" height="20px" width="auto"> </a>
<a href="#">
<img src="images/social_media/instagram.png" height="20px" width="auto">
</a>
</div>
</li>
</ul>
</div>
<!-- /.nav-collapse -->
</nav>
</div>
Preview
I have an example navbar that I wish to modify for my own here. Currently the user's fullname is positioned on the same line like so:
How do I change the fullname position so they are displayed and aligned like this:
I createed an un-ordered list, but I think that is semantically incorrect and we can't put a ul inside a link anyway. It also wasn't working in IE either, so I am back to square one.
Any ideas would be helpful.
body {
padding-top: 102px;
background-color: #4d4d4d;
font-family: 'Lato', verdana, sans-serif;
color: #010101;
}
.container {
width: 1530px;
margin-top: 0;
}
.navbar-fixed-top {
background-color: #fff;
}
.navbar-default .navbar-header {
min-height: 80px;
}
.navbar-default .navbar-header button.hamburger-icon {
margin-top: 20px;
}
.navbar-default .navbar-brand {
color: #010101;
padding-top: 5px;
}
/* searchbox */
.navbar-nav > .dropdown.search .input-group {
padding-top: 15px;
}
.navbar-nav > .dropdown.search .input-group input.form-control {
padding: 0 10px 0 0;
background-color: #fff;
color: #010101;
border-radius: 0;
border: 0;
box-shadow: none;
font-size: 16px;
font-weight: 100;
}
.navbar-nav > .dropdown.search .input-group input.form-control:hover {
background-color: #fff;
}
.navbar-nav > .dropdown.search .input-group-btn button {
padding: 2px;
border: 0;
box-shadow: none;
background-color: #fff;
border-radius: 0;
}
.navbar-nav > .dropdown.search .input-group-btn button:hover {
background-color: #fff;
color: #ff5500;
}
.navbar-nav > .dropdown.search .input-group-btn .glyphicon-search {
font-size: 22px;
}
/* bell notification and dropdown */
.navbar-default .navbar-nav > .open > a.inbox,
.navbar-default .navbar-nav > .open > a.inbox:focus,
.navbar-default .navbar-nav > .open > a.inbox:hover {
background-color: #fff;
padding-top: 15px;
margin-bottom: 5px;
}
.nav > li.dropdown.bell > a:hover,
.nav > li.dropdown.bell > a:focus {
color: #ff5500;
background-color: transparent;
}
.navbar-nav > .dropdown.bell li a:hover {
color: #ff5500;
background-color: transparent;
}
.navbar-nav > .dropdown.bell .badge-count {
background: #ff5500;
margin-top: -24px;
margin-left: -20px;
height: 1.7em;
}
.navbar-nav > li > .dropdown-menu.bell {
background-color: #f8f8f8;
border-radius: 0;
}
.navbar-nav > li > .dropdown-menu.bell li a {
padding-top: 5px;
padding-bottom: 5px;
white-space: normal !important;
width: 350px;
}
.navbar-nav > li > .dropdown-menu.bell li a span.info {
display: block;
padding: 0 5px 0 5px;
}
.navbar-nav > li > .dropdown-menu.bell li.divider {
padding: 0;
margin: 0 20px;
}
.navbar-nav > li > .dropdown-menu.bell .label {
background-color: transparent;
color: #aaa;
font-weight: 100;
}
/* bell notification and dropdown caret */
.navbar-nav > li > .dropdown-menu.bell:before {
position: absolute;
top: -10px;
right: 9%;
display: inline-block;
border-right: 10px solid transparent;
border-bottom: 10px solid #ccc;
border-left: 10px solid transparent;
border-bottom-color: rgba(0, 0, 0, 0.2);
content: '';
}
.navbar-nav > li > .dropdown-menu.bell:after {
position: absolute;
top: -9px;
right: 9%;
display: inline-block;
border-right: 9px solid transparent;
border-bottom: 9px solid #f8f8f8;
border-left: 9px solid transparent;
content: '';
}
/* create profile button */
.navbar-nav > .dropdown.create-profile a.create-profile-btn {
width: 200px;
padding: 12px;
margin-top: 18px;
}
.navbar-nav > .dropdown.create-profile a.btn-default {
background-color: #ff5500;
border-color: #ff5500;
color: #fff;
}
.navbar-nav > .dropdown.create-profile a.btn-default:hover,
.navbar-nav > .dropdown.create-profile a.btn-default:focus,
.navbar-nav > .dropdown.create-profile a.btn-default:active {
color: #fff;
border-color: 0;
/*set the color you want here*/
}
/* user login and dropdown */
.navbar-nav > .user-logged-in span.firstname {
font-size: 16px;
color: #010101;
}
.navbar-nav > .user-logged-in span.surname {
font-size: 16px;
color: #010101;
}
.navbar-nav > .user-logged-in .dropdown-menu.access-list {
width: 100%;
border-radius: 0;
border: 0;
background-color: #f8f8f8;
font-size: 14px;
}
.navbar-nav > .user-logged-in .dropdown-menu.access-list li a {
margin: 5px 0px;
color: #010101;
}
.navbar-nav > .user-logged-in .dropdown-menu.access-list li a:hover {
background-color: transparent;
color: #ff5500;
}
.navbar-nav > .user-logged-in .dropdown-menu.access-list li.divider {
padding: 0;
margin: 0 20px;
}
.fullname {
float: right;
padding-right: 10px;
}
.drop-arr {
float: right;
padding-top: 10px;
}
span.avatar {
padding-right: 90px;
}
/* Large desktop */
#media (max-width: 1590px) {
.container {
width: auto;
}
}
/* Portrait tablet to landscape and desktop */
#media (max-width: 979px) {}
/* Landscape phone to portrait tablet */
#media (max-width: 768px) {
.container {
width: auto;
}
.navbar-default .navbar-brand {
font-size: 40px;
}
/* bell notification and dropdown */
.navbar-default .navbar-nav > .open > a.inbox,
.navbar-default .navbar-nav > .open > a.inbox:focus,
.navbar-default .navbar-nav > .open > a.inbox:hover {
width: 100% !important;
background-color: #e7e7e7;
margin-bottom: 0px;
}
.navbar-nav > li > .dropdown-menu.bell li a {
width: 100%;
}
.navbar-nav > li > .dropdown-menu.bell:before,
.navbar-nav > li > .dropdown-menu.bell:after {
display: none;
}
.navbar-nav > li > .dropdown-menu.bell li a {
text-align: left;
}
.navbar-nav > .dropdown.bell,
.navbar-nav > .user-logged-in {
text-align: center;
}
/* searchbox */
.navbar-nav > .dropdown.search {
padding-left: 10px;
padding-right: 10px;
margin-top: 0;
width: 100%;
overflow: hidden;
}
.navbar-nav > .dropdown.search .input-group {
padding-top: 0;
}
}
/* Landscape phones and down */
#media (max-width: 480px) {
.navbar-default .navbar-brand {
font-size: 30px;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>
<div class="container">
<div class="navbar navbar-default navbar-fixed-top navbar-md" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle hamburger-icon" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<h1>
<img src="logo.png" height="30" width="180">
</h1>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<!-- search bar -->
<li class="dropdown search">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search name or keyword" name="q">
<div class="input-group-btn">
<button class="btn btn-default" type="submit">
<img src="https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/search-128.png" height="30" width="30" class=" avatar-img img-square">
</button>
</div>
</div>
</form>
</li>
<!-- notification bell -->
<li class="dropdown bell">
<a href="#" class="dropdown-toggle inbox" data-toggle="dropdown">
<img src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-ios7-bell-outline-128.png" height="45" width="45" class=" avatar-img img-square">
<span class="badge badge-count">1</span>
</a>
<ul class="dropdown-menu bell" role="menu">
<li><span class="label label-default">4:00 AM</span><span class="info">Favourites Snippet</span>
</li>
<li class="divider"></li>
<li><span class="label label-warning">4:30 AM</span><span class="info">Email marketing</span>
</li>
<li class="divider"></li>
<li><a href="#"><span class="label label-warning">5:00 AM</span>
<span class="info">
Subscriber focused email design
Extra sample line
Extra sample line
Extra sample line
</span></a>
</li>
<li class="divider"></li>
<li>View All
</li>
</ul>
</li>
<!-- create profile button -->
<!-- <li class="dropdown create-profile">
<a class="btn btn-default btn-lg create-profile-btn" href="#" role="button">Create a profile</a>
</li> -->
<!-- user login information -->
<li class="dropdown user-logged-in">
<a href="#" class="dropdown-toggle username" data-toggle="dropdown">
<span class="avatar"><img src="https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/user_male2-128.png" height="50" width="50" ></span>
<span class="drop-arr"><img src="https://cdn0.iconfinder.com/data/icons/slim-square-icons-basics/100/basics-08-128.png" height="20" width="20" ></span>
<span class="fullname">
<span class="firstname">Jacky</span>
<br><span class="surname">Smith</span>
</span>
</a>
<ul class="dropdown-menu access-list" role="menu">
<li>ssdfsdf
</li>
<li class="divider"></li>
<li>fsfsdfs
</li>
<li class="divider"></li>
<li>sfsfsf
</li>
<li class="divider"></li>
<li>fsdfsdsd
</li>
<li class="divider"></li>
<li>dlfjsdlfjs
</li>
</ul>
</li </ul>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<p>dfsjfhskfs</p>
<!-- <div class="chevron right">
</div>
<div style="height: 1em;">
</div> -->
</div>
</div>
</div>
</div>
A simple </br> would do:
<span>First Name </br> <strong>Last Name<strong> </span>
.navbar-login {
width: 305px;
padding: 10px;
padding-bottom: 0px;
}
.navbar-login-session {
padding: 10px;
padding-bottom: 0px;
padding-top: 0px;
}
.icon-size {
font-size: 87px;
}
.glyphicon-user {
position: absolute !important;
margin: -5px 0 0;
left: 5px;
top: 50% !important;
}
.glyphicon-chevron-down {
position: absolute !important;
margin: -5px 0 0;
right: 5px;
top: 50% !important;
}
.dropdown .dropdown-toggle {
position: relative;
padding-right: 35px;
padding-left: 35px;
}
.name {
display: block;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>
<div 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="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a target="_blank" href="#" class="navbar-brand">My sApp.</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Inicio
</li>
<li class="active">Inspirado en este ejemplo
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">DropDown
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>Link 2
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle text-right username" data-toggle="dropdown">
<span class="glyphicon glyphicon-user"></span>
<span class="name">Nombre</span>
<strong class="name">lastname</strong>
<span class="glyphicon glyphicon-chevron-down"></span>
</a>
<ul class="dropdown-menu">
<li>
<div class="navbar-login">
<div class="row">
<div class="col-lg-4">
<p class="text-center">
<span class="glyphicon glyphicon-user icon-size"></span>
</p>
</div>
<div class="col-lg-8">
<p class="text-left"><strong>Nombre Apellido</strong>
</p>
<p class="text-left small">correoElectronico#email.com</p>
<p class="text-left">
Actualizar Datos
</p>
</div>
</div>
</div>
</li>
<li class="divider"></li>
<li>
<div class="navbar-login navbar-login-session">
<div class="row">
<div class="col-lg-12">
<p>
Cerrar Sesion
</p>
</div>
</div>
</div>
</li>
</ul>
</li>
</ul>
</div>
</div>
You can do this by changing a little bit the structure of this :
<span class="nombre">
<span>Nombre</span>
<span><strong>lastname</strong></span>
</span>
And the relevant CSS :
.username .nombre {width: 75px; display: inline-block; text-align: right; margin-right: 10px;}
.glyphicon { vertical-align: top; padding-top: 15px; }
.glyphicon:first-child { padding-top: 10px}
See this fiddle
<span style="float:right">Nombre</span>
<p class="clear">
<span style="float:right"><strong>lastname</strong></span>
in css add
clear: both;
height: 0;
margin: 0;
padding: 0;
and use it in situations like this :)
you could also use something like this
<span style="float:right">Nombre</span>
<br/>
<span style="float:right"><strong>lastname</strong></span>
but i think that will separate them too much
I have created a custom height navbar with a large logo image and I'm sure I have missed something in the CSS because when the dropdown menu is clicked it jumps higher on the page until it is clicked a second time, and then the link works.
There is a "working" example at http://machadodesign.com/bootstrap/
Here is the CSS I have for the navbar
#media (min-width: 992px) {
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
min-height: 85px;
bottom: 0 ;
}
}
.navbar-nav li a {
padding-top: 30px;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
color: #333;
background-color: #e7e7e7;
}
.navbar-default .navbar-nav .active a {
background: #f8f8f8;
text-shadow: 0px 0px 9px rgba(144, 169, 210, 1) !important;
}
.dropdown .active {
text-shadow: 0px 0px 9px rgba(144, 169, 210, 1) !important;
}
.navbar-brand {
height: inherit;
padding: 5px 15px;
}
.navbar-brand a{
padding-top: 0 !important;
}
.navbar-brand img {
height: 50px
}
.dropdown li, .dropdown li:hover {
/* padding-top: 10px;*/
padding-bottom: 0px !important;
/* min-height: 40px;*/
}
.dropdown li a {
padding-top: 10px;
padding-bottom: 0px !important;
min-height: 40px;
}
.logo-tag {
font-size: 10px;
font-style: italic;
font-weight: 700;
line-height: 14px;
letter-spacing: 0.04em;
}
#media (min-width: 768px) {
.logo-tag {
font-size: 13px;
font-style: italic;
font-weight: 700;
line-height: 14px;
letter-spacing: 0.04em;
}
.navbar-brand img {
height: 58px
}
.navbar-brand {
height: inherit;
padding: 3px 15px;
}
}
Here is the HTML of the navbar as I have it.
<nav role="navigation" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid social-bar hidden-xs">
<div class="container">
<div class="row">
<div class="col-sm-9">Questions? Need help? Call now: (866) 214-6128</div>
<div class="col-sm-3 text-right">
<ul class="list-inline">
<li><i class="fa fa-lg fa-facebook"></i></li>
<li><i class="fa fa-lg fa-twitter"></i></li>
<li><i class="fa fa-lg fa-google-plus"></i></li>
<li><i class="fa fa-lg fa-youtube"></i></li>
<li><i class="fa fa-lg fa-rss"></i></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" id="myNavbar" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="images/logo.png"><span class="logo-tag">Customer and Class Management Made Easy!</span>
</div>
<!-- Collection of nav links and other content for toggling -->
<div id="navbarCollapse" class="collapse navbar-collapse navbar-right">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown">
Features <span class="caret"></span>
<ul class="dropdown-menu navbar-right">
<li>Features Overview</li>
<li>Easy Startup!</li>
<li>Easy to Use!</li>
<li>Easy to Customize!</li>
<li>Power-user Features</li>
<li>Multi-country</li>
<li>Lots of Add-ons</li>
</ul>
</li>
<li class="dropdown">
Try it Free <span class="caret"></span>
<ul class="dropdown-menu">
<li>Take a Test Drive</li>
<li>Get Started Today</li>
</ul>
</li>
<li>Pricing</li>
<li>Contact Us</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><i class="fa fa-lock"></i> Login</li>
</ul>
</div>
</div>
</nav>
Any help is greatly appreciated.
The problem is right at the top of your provided CSS:
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
min-height: 85px;
bottom: 0 ;
}
It only retains its min-height if it is hovered over or in focus, which is why the click is causing the jump (triggering focus). Change it to this:
.navbar-default .navbar-nav > li > a {
min-height: 85px;
bottom: 0 ;
}