Don't want recursive :after for my ul li dropdown menu - html

I'm stuck with this annoying problem. I have a nav in which there is a dropdown menu, composed by many <ul> in each <li>of the first <ul>
I have an :after effect for the main <ul>. It set a separator, but I don't want this separator in the <ul><li> of the <ul><li>.
Here is my code
nav ul li {
-webkit-transition: background-color .3s;
transition: background-color .3s;
float: left;
padding: 0;
transition:0.5s all;
position: relative;
display: block;
letter-spacing: -1px;
}
nav ul li:after {
height:60%;
content:'';
border-left: solid 1px rgba(255, 255, 255,0.3);
position: absolute;
transform: translateX(-50%) translateY(-50%);
left: 0px;
top: 50%;
transition:0.5s all;
-webkit-transition: 0.5s all;
}
nav ul li ul li:after {
content:none!important;
height:0%!important;
content:unset;
border-left: unset;
position: unset;
transform: unset;
left: unset;
top: unset;
}
<header id="header">
<nav>
<div class="bar">
<div class="brand-logo">
Paris Avenir</div>
<ul id="nav-normal" class="right">
<li>Aide/Tutos/Astuces<i class="fas fa-angle-down"></i>
<ul class="dropdown">
<li>J'arrive à Paris</li>
<li>Impositions</li>
<li>Fonctionnement de la mairie</li>
<li>PLU</li>
<li>Emploi/Formation</li>
</ul>
</li>
<li>Nos actions<i class="fas fa-angle-down"></i>
<ul class="dropdown">
<li>Décryptage des conseils municipaux</li>
<li>Étude des budgets</li>
<li>Actualités</li>
</ul></li>
<li><a id="search"><i class="fas fa-search"></i></a></li>
</ul>
</div>
</nav>
</header>
This seems so easy but it doens't work.
Thanks you,
Matthieu

You want to select only the ul with the id of nav-normal and use the child combinator CSS selector:
ul#nav-normal > li::after
You can read more about it here: https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator
Note that I've altered the styling of the ::after elements to make then more easily visible
nav ul li {
-webkit-transition: background-color .3s;
transition: background-color .3s;
float: left;
padding: 0;
transition: 0.5s all;
position: relative;
display: block;
letter-spacing: -1px;
}
ul#nav-normal>li::after {
content: '[:after content]';
color: red;
}
<header id="header">
<nav>
<div class="bar">
<div class="brand-logo">Paris Avenir</div>
<ul id="nav-normal" class="right">
<li>
Aide/Tutos/Astuces<i class="fas fa-angle-down"></i>
<ul class="dropdown">
<li>J'arrive à Paris</li>
<li>Impositions</li>
<li>Fonctionnement de la mairie</li>
<li>PLU</li>
<li>Emploi/Formation</li>
</ul>
</li>
<li>
Nos actions<i class="fas fa-angle-down"></i>
<ul class="dropdown">
<li>Décryptage des conseils municipaux</li>
<li>Étude des budgets</li>
<li>Actualités</li>
</ul>
</li>
<li><a id="search"><i class="fas fa-search"></i></a></li>
</ul>
</div>
</nav>
</header>

Related

Trying to center navigation bar with CSS

Hello all I'm fairly new to CSS and learning a lot everday, but I'm having some issues centering my "megamenu" navigation bar. I've searched all over and so far none of the things I've tried seem to work with this, it's still mostly left aligned. I've got it set up right now here: https://www.shrinkabulls.com/megamenu/test.html
The code is below. Any help would be greatly appreciated. Thank you!
HTML:
<!-- ...:::: Start Header Section:::... -->
<header class="header-section d-lg-block d-none">
<!-- Start Bottom Area -->
<div class="header-bottom sticky-header">
<div class="container">
<!-- Header Main Menu -->
<div class="main-menu">
<nav>
<ul>
<li>
Home
</li>
<li class="has-dropdown">
Available Bulldogs <i class="fa fa-angle-down"></i>
<!-- Sub Menu -->
<ul class="sub-menu">
<li>Puppies</li>
<li>Adults</li>
<li>French Bulldogs</li>
<li>Stud Service</li>
<li>Past Puppies</li>
</ul>
</li>
<li class="has-dropdown has-megaitem">
Bulldog Info <i class="fa fa-angle-down"></i>
<!-- Mega Menu -->
<div class="mega-menu">
<ul class="mega-menu-inner">
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<a class="mega-menu-item-title">General</a>
<ul class="mega-menu-sub">
<li>Is a bulldog right for you?</li>
<li>Buying a Bulldog Puppy</li>
<li>Naming Your Bulldog</li>
<li>Pricing/Home Approval</li>
<li>Bulldogs and Children</li>
<li>Bulldogs and Cats</li>
<li>Breeding</li>
<li>Showing</li>
<li>Bulldog Merchandise</li>
<li>SCAM Alert</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<a class="mega-menu-item-title">Care</a>
<ul class="mega-menu-sub">
<li>Health/Vet</li>
<li>Nutrition</li>
<li>Supplements</li>
<li>Teeth Cleaning</li>
<li>Spay/Neuter</li>
<li>Heat Stroke</li>
<li>Overweight Bulldogs</li>
<li>Newborn Bulldogs</li>
<li>Pet Insurance</li>
<li>Clothes for Bulldogs</li>
</ul>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<a class="mega-menu-item-title">Breed</a>
<ul class="mega-menu-sub">
<li>History</li>
<li>Standard</li>
<li>Colors</li>
<li>Rare Colors</li>
<li>AKC Color Chart</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<a class="mega-menu-item-title">Training</a>
<ul class="mega-menu-sub">
<li>Crate Training</li>
<li>House Training</li>
<li>Training With Treats</li>
<li>Obedience Training</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<a class="mega-menu-item-title">Links</a>
<ul class="mega-menu-sub">
<li>Links</li>
<li>Sitemap</li>
</ul>
</li>
</li>
</ul>
</div>
</li>
<li class="has-dropdown">
Media <i class="fa fa-angle-down"></i>
<!-- Sub Menu -->
<ul class="sub-menu">
<li>Celebrities With Bulldogs</li>
<li>In The Press</li>
<li>Bulldog Actors</li>
<li>Photos</li>
<li>Videos</li>
</ul>
</li>
<li class="has-dropdown has-megaitem">
Our Dogs <i class="fa fa-angle-down"></i>
<!-- Mega Menu -->
<div class="mega-menu">
<ul class="mega-menu-inner">
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<ul class="mega-menu-sub">
<li>Int Ch Ace</li>
<li>Blue Legacy</li>
<li>Home Brew/JAX</li>
<li>Blue Moon</li>
<li>Ace Jr</li>
<li>Prince</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<ul class="mega-menu-sub">
<li>Ivy</li>
<li>Mystic</li>
<li>Titan</li>
<li>Tundra</li>
<li>Katana</li>
<li>Winston</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<ul class="mega-menu-sub">
<li>Blue Legend</li>
<li>The Boys</li>
<li>Spike</li>
<li>Chocolate Reese</li>
<li>Oscar</li>
<li>Blue Tux</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<ul class="mega-menu-sub">
<li>Dreama</li>
<li>Blue Eyed</li>
<li>Standard Color</li>
<li>Lilac Crave</li>
<li>Chocolate Crave</li>
<li>Black Crave</li>
</ul>
</li>
<!-- Mega Menu Sub Link -->
<li class="mega-menu-item">
<ul class="mega-menu-sub">
<li>Blue Crave</li>
<li>Blue Merle</li>
<li>Exotics</li>
</ul>
</li>
</li>
</ul>
</div>
</li>
<li class="has-dropdown">
About Us <i class="fa fa-angle-down"></i>
<!-- Sub Menu -->
<ul class="sub-menu">
<li>About Shrinkabulls</li>
<li>Awards</li><li>
<li>Contact</li>
</ul>
</li>
</ul>
</nav>
</div> <!-- Header Main Menu Start -->
</div>
</div> <!-- End Bottom Area -->
</header> <!-- ...:::: End Header Section:::... -->
CSS:
.main-menu {
position: relative;
}
.main-menu nav > ul > li {
position: relative;
display: inline-block;
}
.main-menu nav > ul > .has-dropdown {
margin-right: 5px;
}
.main-menu nav > ul > .has-dropdown:last-child {
margin-right: 0;
}
.main-menu nav > ul > .has-megaitem {
position: static;
}
.main-menu nav > ul > li > a {
display: block;
line-height: 24px;
padding: 10px 10px;
font-size: 20px;
text-transform: capitalize;
font-weight: 500;
color: #993b00;
}
.main-menu nav > ul > li > a:hover, .main-menu nav > ul > li > a.active {
background: #993b00;
color: #FFF;
}
.sub-menu > li > a,
.mega-menu-sub > li > a {
font-size: 18px;
display: block;
line-height: 35px;
text-transform: capitalize;
color: #000;
position: relative;
transition: all 0.3s ease 0s;
}
.sub-menu > li > a::after,
.mega-menu-sub > li > a::after {
position: absolute;
content: "";
top: 50%;
left: 0;
transform: translate(0px, -50%);
height: 5px;
width: 5px;
border-radius: 50%;
background: #993b00;
visibility: hidden;
opacity: 0;
transition: all 0.3s ease 0s;
}
.sub-menu > li > a:hover,
.mega-menu-sub > li > a:hover {
color: #993b00;
transform: translateX(10px);
}
.sub-menu > li > a:hover::after,
.mega-menu-sub > li > a:hover::after {
transform: translate(-10px, -50%);
visibility: visible;
opacity: 1;
}
.sub-menu {
position: absolute;
min-width: 230px;
padding: 25px 20px;
background: #ece2a5;
box-shadow: 0 3px 11px 0 rgba(0, 0, 0, 0.1);
transform: perspective(600px) rotateX(-20deg);
transform-origin: 0 0 0;
left: 0;
right: auto;
opacity: 0;
visibility: hidden;
transition: 0.5s;
z-index: 99;
top: 100%;
text-align: left;
}
.mega-menu {
position: absolute;
min-width: 100%;
padding: 25px 30px 30px 30px;
background: #ece2a5;
box-shadow: 0 3px 11px 0 rgba(0, 0, 0, 0.1);
transform: perspective(600px) rotateX(-20deg);
transform-origin: 0 0 0;
left: 0;
right: 0;
opacity: 0;
visibility: hidden;
transition: 0.5s;
z-index: 99;
top: 100%;
text-align: left;
}
.mega-menu-inner {
display: flex;
justify-content: space-between;
}
.mega-menu-item-title {
font-size: 20px;
line-height: 24px;
text-transform: uppercase;
font-weight: 700;
display: block;
margin-bottom: 13px;
color: #333;
}
.mega-menu-item-title:hover {
color: #261146;
}
.mega-menu-sub > li {
display: block;
}
.main-menu nav > ul > li:hover .sub-menu,
.main-menu nav > ul > li:hover .mega-menu {
opacity: 1;
visibility: visible;
transform: perspective(600px) rotateX(0deg);
}
It seems to me that the whole menu is not centered... why don't you try to add
.main-menu > nav > ul {
display: flex;
justify-content: center;
}
if this is not what you are looking for, please clarify!
Edit: I'm glad that worked, I corrected the css so the outcome you mention no long happens.
If you are going to keep working with css, maybe try some methodology or convention to name elements to avoid that something like this happens to you in the future BEM for instance is great or you can read something about atomic design.
What exactly are you trying to center? If it is the menu text, just use the
text-align
CSS attribute (https://developer.mozilla.org/en-US/docs/Web/CSS/text-align).
for example, in class header-bottom, you would have the following (text-align:center added to bottom):
.header-bottom {
background: #ece2a5;
position: relative;
box-shadow: 0 3.4px 2.7px rgb(0 0 0 / 1%), 0 8.7px 6.9px rgb(0 0 0 / 1%), 0 17.7px 14.2px rgb(0 0 0 / 1%), 0 36.5px 29.2px rgb(0 0 0 / 1%), 0 100px 80px rgb(0 0 0 / 2%);
text-align: center;
}
If it is something else you are trying to center, please explain in more detail, and I will edit this answer accordingly.

How to limit formatting of navigation menu to just the main menu and NOT to the items in the drop-downs. HTML, CSS

Hi, if you look at the above screenshot you can see I have added in code to make a small bar transition across when hovering over items in the navigation bar.
However, this bar also appears when I hover over items in the drop down menu. For example, when hovering over "Stock 1" the bar appears and obviously looks awful.
How can I make it so that this bar only appears on the items in the main menu and NOT in the drop down menu's.
Please see HTML code below:
<header>
<div class="container-fluid">
<div class="logo">
<img src="images/japan_flag.gif" alt="" height="31" width="41">
</div>
<div class="container">
<nav role="navigation">
<ul class="mainmenu">
<li>Home</li>
<li>About Us</li>
<li>Stock
<ul class="dropdown">
<li>Stock 1</li>
<li>Stock 2</li>
</ul>
</li>
<li>Enquiries</li>
<li>Contacts</li>
</ul>
</nav>
</div>
<div id="mobile-menu-wrap"></div>
</div>
</header>
Please see CSS below:
nav a {
text-decoration: none;
text-transform: uppercase;
font-family: "Oswald", sans-serif;
}
nav {
font-family: monospace;
}
nav ul {
list-style: none;
margin: 0;
margin-top: 30px;
padding-left: 45%;
}
nav ul li {
color: #fff;
display: block;
float: left;
padding: 1rem;
position: relative;
text-decoration: none;
transition-duration: 0.5s;
}
nav ul li a {
color: #fff;
}
nav ul li a:hover {
cursor: pointer;
color: rgb(199, 50, 13);
transition-duration: 0.3s;
}
nav ul li ul {
visibility: hidden;
background: rgb(199, 50, 13);
opacity: 0;
min-width: 100%;
position: absolute;
transition: all 0.5s ease;
margin-top: 1rem;
display: block;
min-width: 100%;
white-space: nowrap;
z-index: 100;
padding: 9% 9%;
text-align: left;
line-height: 10px;
padding-top: 8px;
}
nav ul li:hover > ul,
nav ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
nav ul li ul li a:hover {
color: black;
}
nav ul li ul li {
clear: both;
width: 100%;
}
nav ul li a::after {
content: '';
display: block;
height: 5px;
background-color: rgb(199, 50, 13);
position: relative;
bottom: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
nav ul li a:hover::after {
width:100%;
}
Any help with this would be hugely appreciated as I have tried for ages to research and figure this out. I am very new to HTML, CSS and any sort of coding in general so apologies.
You can give class to <a> on which you want to apply style..
You can do like this.
<header>
<div class="container-fluid">
<div class="logo">
<img src="images/japan_flag.gif" alt="" height="31" width="41">
</div>
<div class="container">
<nav role="navigation">
<ul class="mainmenu">
<li><a class="abc" href="#">Home</a></li>
<li><a class="abc" href="#">About Us</a></li>
<li><a class="abc" href="#">Stock</a>
<ul class="dropdown">
<li>Stock 1</li>
<li>Stock 2</li>
</ul>
</li>
<li>Enquiries</li>
<li>Contacts</li>
</ul>
</nav>
</div>
<div id="mobile-menu-wrap"></div>
</div>
And in css file you can do like this:
.abc:hover{
cursor: pointer;
color: rgb(199, 50, 13);
transition-duration: 0.3s;
}

Menu in CSS using <ol>

When I hover a Media, E-sport, Community I want to see <li> under them. I get it with the rgb opacity. But it's a pity that when I hover AN <li> element which is opacity 0 it appears. I only want to do it when I hover ol li a. Someone know's the answer?
Here's my code (Menu with lists)
.Menu ol {
display: inline-block;
padding: 0;
margin: 0;
line-height: 1;
}
.Menu ol>li>ul>li>a {
margin-left: 0;
padding: 0;
}
.Menu ol>li {
float: left;
padding: 0;
list-style-type: none;
}
.Menu ol>li>ul>li>a {
color: rgba(55, 255, 255, 0);
transition: .5s ease-in-out;
}
.Menu ol>li:hover>ul>li>a {
color: rgba(55, 255, 255, 1);
transition: .5s ease-in-out;
background-color: rgb(0, 0, 205, 1);
}
.Menu ol>li>ul>li {
clear: both;
margin-left: 90px;
}
.Menu ol>li>ul>li {
clear: both;
margin: 0;
list-style-type: none;
padding: 0;
}
.Menu ol>li>ul>li>a {
padding-left: 0;
margin: 0;
}
Article {
width: 1920px;
height: 957px;
}
<div class="Menu">
<ol>
<li>Media
<ul>
<li>Facebook</li>
<li>Facebook</li>
<li>Facebook</li>
</ul>
</li>
<li>E-sport
<ul>
<li>Facebook</li>
<li>Facebook</li>
<li>Facebook</li>
</ul>
</li>
<li>Community
<ul>
<li>Facebook</li>
<li>Facebook</li>
<li>Facebook</li>
</ul>
</li>
</ol>
</div>
To be honest I find the whole ".Menu ol>li:hover>ul>li>a.. " and so on pure madness, its messy and unclear, much better effects you will get when using pure divs and classes, also use display: none, so it actually takes away the elements unless you set it to something, here is the code:
Edited: Use opacity: 0 and overflow: hidden, it works with transtition
Edit2: Actually simple height: 0 + overflow hidden will give you nice transtition in AND out, it got to have fixed height on hover thou.
<div class="Menu">
<div class="Menu-item-container">
Media
<div class="hover-items">
<div>Facebook</div>
<div>Facebook</div>
<div>Facebook</div>
</div>
</div>
<div class="Menu-item-container">
E-sport
<div class="hover-items">
<div>Facebook</div>
<div>Facebook</div>
<div>Facebook</div>
</div>
</div>
<div class="Menu-item-container">
Community
<div class="hover-items">
<div>Facebook</div>
<div>Facebook</div>
<div>Facebook</div>
</div>
</div>
</div>
<style>
.Menu {
display: flex;
justify-content: space-around;
width: 300px;
}
a {
text-decoration: none;
}
.hover-items {
transition: .5s ease-in-out;
height: 0;
overflow: hidden;
}
.Menu-item-container {
width: 100px;
text-align: center;
}
.Menu-item-container:hover .hover-items{
height: 100px;
}
</style>
Codepen: https://codepen.io/Raitar/pen/QOZgoV?editors=1100
Dude i'm sorry but your code is madness. why combine ol and ul.
here i give you free mine :
body{
width:100%;
height:100%;
margin:0;
}
ul{
list-style:none;
padding:0;
}
a{
text-decoration:none;
}
.menu {
width:100%;
height: 33px;
background: #000;
position:relative;
}
.menu ul:not(.sub-menu):not(.micro){
margin:auto;
display:flex;
}
.menu ul li{
position:relative;
flex:1;
}
.menu a{
text-align:center;
display:block;
line-height: 33px;
margin-right: 40px;
color:#fff;
padding: 0 15px;
}
.sub-menu{
width:100%;
display:none;
position: absolute;
transform:translateY(0);
background: #ccc;
transition: all 300ms;
z-index:2;
}
.sub-menu a{
margin:10px 0;
}
.micro{
top:-10px;
width:100%;
opacity:0;
transform: translate(100%, 0);
position: absolute;
background: orangered;
z-index:1;
transition: all 300ms;
}
.micro a{
color:#fff;
}
.menu ul li a:hover + ul.sub-menu {
display:block;
}
.sub-menu:hover{
transform:translateY(5%);
display:block;
}
.sub-menu a:hover + ul.micro {
opacity:1;
}
.micro:hover{
opacity:1;
}
<div class="menu">
<ul>
<li>MEDIA
<ul class="sub-menu">
<li>FACEBOOK
<ul class="micro">
<li>TWITTER</li>
<li>TWITTER</li>
<li>TWITTER</li>
</ul>
</li>
<li>FACEBOOK</li>
<li>FACEBOOK</li>
</ul>
</li>
<li>E-SPORT
<ul class="sub-menu">
<li>FACEBOOK</li>
<li>FACEBOOK</li>
<li>FACEBOOK</li>
</ul>
</li>
<li>COMMUNITY
<ul class="sub-menu">
<li>FACEBOOK</li>
<li>FACEBOOK</li>
<li>FACEBOOK</li>
</ul>
</li>
</ul>
</div>

Bootstrap Sub menu to stretch full screen and overlay the whole page

I've made a JSFiddle to illustrate what I have at the moment. Please view my code here:
Some of my CSS snippet code:
.subnav {
display: none;
position: absolute;
//top: 58px;
background: #dfe6e8;
padding: 24px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
transition: all .5s ease;
}
.subnav li {
margin-right: 0px !important;
min-width: 142px;
}
.subnav li a {
padding-bottom: 0px !important;
margin-bottom: 16px;
}
.subnav li:last-child a {
margin-bottom: 0px;
}
.has-dropdown:hover .subnav {
display: block;
}
I'm having problem to make my UL to stretch fullscreen. Here's what I'm trying to achieve as below:
Any help would be appreciated
To achieve this you have to make few structural and css changes. I edited your fiddle and made some changes to the navigation.
Html:
<div class="nav-container">
<nav class="top-bar">
<div class="container-fluid">
<div class="row nav-menu">
<div class="col-xs-12 columns">
<a class="navbar-brand" href="index.html"><img alt="Logo" class="logo logo-light" src="img/logo-light.png"> <img alt="Logo" class="logo logo-dark" src="http://www.subcablenews.com/links/images2/telenor.gif"></a>
<ul class="menu navbar-right">
<li>
ABOUT
</li>
<li class="has-dropdown">
PROGRAMMES
<ul class="subnav">
<li>
Programme 1
</li>
<li>
Programme 2
</li>
<li>
Programme 3
</li>
<li>
Programme 4
</li>
</ul>
</li>
<li class="has-dropdown">
PROJECTS
<div class="subnav subnav-halfwidth fullwidth">
<div class="col-sm-4">
<h6 class="alt-font">Project Lists</h6>
<ul class="subnav subnav-halfwidth">
<li>
Project 1
</li>
<li>
Project 2
</li>
<li>
Project 3
</li>
<li>
Project 4
</li>
</ul>
</div>
<div class="col-sm-4">
<h6 class="alt-font">Project Lists 2</h6><img alt="Logo" class="logo" src="http://www.subcablenews.com/links/images2/telenor.gif"></div>
<div class="col-sm-4">
<h6 class="alt-font">Project Lists 2</h6><img alt="Logo" class="logo" src="http://www.subcablenews.com/links/images2/telenor.gif"></div>
</div>
</li>
<li class="has-dropdown">
MEDIA
<ul class="subnav">
<li>
Media 1
</li>
<li>
Media 2
</li>
<li>
Media 3
</li>
<li>
Media 4
</li>
</ul>
</li>
<li>
CONTACT
</li>
</ul>
<ul class="social-icons text-right">
<li>
<i class="icon social_twitter"></i>
</li>
<li>
<i class="icon social_facebook"></i>
</li>
<li>
<i class="icon social_instagram"></i>
</li>
</ul>
</div>
</div><!--end of row-->
<div class="mobile-toggle">
<i class="icon icon_menu"></i>
</div>
</div><!--end of container-->
</nav>
</div>
Extra Css:
.subnav.fullwidth{
position: absolute;
right: -15px;
top: 58px;
width: 100vw;
background: #F6F4F4;
padding: 48px 64px 48px;
box-shadow: inset 0 1px 0 #e2e3df, 0 3px 6px rgba(113,111,111,.7);
-webkit-transform: translateX(0);
-moz-transform: translateX(0);
-ms-transform: translateX(0);
-o-transform: translateX(0);
transform: translateX(0);
-webkit-transition: opacity .3s 0s, visibility 0s 0s;
-moz-transition: opacity .3s 0s, visibility 0s 0s;
transition: opacity .3s 0s, visibility 0s 0s;
/* box-shadow: 1px 2px 5px #7D7D7D; */
}
.row{margin:0}
.top-bar .logo {
width: 150px;
}
.subnav li{float:none; display: block;}
Here is Updated Fiddle. Make sure you check the html as well. Because I made some changes in that too.
Read this to get better understand about bootstrap navigation. Hope this helps you.
It's because the parent elements aren't at 100% width. You can override this by using width:100vw; on any element that you want to take up the full width. Also, try and remember next time to only include css on your fiddle that's relevant to the html at question. It's a lot to sort through for someone trying to help when you include your entire stylesheet.

How make an inside element ignore the style

<ul id="login">
<li>User></li>
<li>Logout></li>
</ul>
I did make my menu and sub menu work ok. But the last item came from a Partial view doesnt show because this line
/* hide the second level menu */
.menu ul {
display: none;
I try putting using :not selector, but then show in a wrong format and first sub menu stop working.
.menu ul:not(#login)
On this sample, all four <LI> element should have same format and first one display the submenu.
Also try creating a different class for the second UL and ignore me.
body {
background: black;
}
.menu {
display: block;
}
.menu li {
display: inline-block;
position: relative;
z-index: 100;
}
.menu li a {
font-weight: 600;
text-decoration: none;
padding: 11px;
display: block;
color: #ffffff;
-webkit-transition: all 0.2s ease-in-out 0s;
-moz-transition: all 0.2s ease-in-out 0s;
-o-transition: all 0.2s ease-in-out 0s;
-ms-transition: all 0.2s ease-in-out 0s;
transition: all 0.2s ease-in-out 0s;
}
.menu li a:hover, .menu li:hover > a {
color: #ffffff;
background: #9CA3DA;
}
/* hide the second level menu */
.menu ul {
display: none;
margin: 0;
padding: 0;
width: 150px;
position: absolute;
top: 43px;
left: 0px;
background: #ffffff;
}
/* display second level menu on hover */
.menu li:hover > ul {
display: block;
}
.menu ul li {
display: block;
float: none;
background: black;
margin: 0;
padding: 0;
}
.menu ul li a {
font-size: 12px;
font-weight: normal;
display: block;
color: #797979;
border-left: 3px solid #ffffff;
background: #ffffff;
}
.menu ul li a:hover, .menu ul li:hover > a {
background: #f0f0f0;
border-left: 3px solid #9CA3DA;
color: #797979;
}
<nav>
<ul class="menu">
<li>
<i class="icon-home"></i>HOME
<ul class="sub-menu">
<li>Sub-Menu 1</li>
<li>Sub-Menu 2</li>
<li>Sub-Menu 3</li>
</ul>
</li>
<li><i class="icon-user"></i>ABOUT</li>
<li>
<ul id="login">
<li>User</li>
<li>Logout</li>
</ul>
</li>
</ul>
</nav>
Can you explain why you didn't put Userand Logout at the same level of Home and About like that:
<nav>
<ul class="menu">
<li>
<i class="icon-home"></i>HOME
<ul class="sub-menu">
<li>Sub-Menu 1</li>
<li>Sub-Menu 2</li>
<li>Sub-Menu 3</li>
</ul>
</li>
<li>
<i class="icon-user"></i>ABOUT
</li>
<li>User</li>
<li>Logout</li>
</ul>
</nav>
It should work !
EDIT
With the following modification of css, your menu should work.
.menu ul.sub-menu li a { ... }
.menu ul.sub-menu li a:hover, .menu ul.sub-menu li:hover > a { ... }
#login {padding: 0; text-transform: uppercase;}
codepen
Here's the code:
<nav>
<ul class="menu">
<li>
<i class="icon-home"></i>HOME
<ul class="sub-menu">
<li>Sub-Menu 1</li>
<li>Sub-Menu 2</li>
<li>Sub-Menu 3</li>
</ul>
</li>
<li><i class="icon-user"></i>ABOUT</li>
<li id="user">USER</li>
<li id="logout">LOGOUT</li>
</ul>
</nav>
That should do it!
You've placed the ABOUT link in a list item by itself.
Here's the proper HTML:
<nav>
<ul class="menu">
<li>
<i class="icon-home"></i>HOME
<ul class="sub-menu">
<li>Sub-Menu 1</li>
<li>Sub-Menu 2</li>
<li>Sub-Menu 3</li>
</ul>
</li>
<li>
<i class="icon-user"></i>ABOUT
<ul id="login">
<li>User</li>
<li>Logout</li>
</ul>
</li>
</ul>
</nav>