Submenus are not displayed correctly - css

I would like to have the same result as this example.
For the sub-menus (portfolio, contact, etc...): a background that takes the whole width.
The titles of the submenus are almost centered
In my sidebar, I have two rubrics: Category and Markets.
Here is my example...
My problem is that the width of the submenus (Portfolio, Contact, Indice, etc..) are not wide.
There is white to the left.
I would also like to center the menu subtitles like the example I showed you.
I made an illustration of the menu here -> Stackblitz
Thank you a lot for your help and your time.
HTML
<div class="sidebar" [class.sidebar-close]="!openSidebar" >
<div class="logo-details">
<img src="https://zupimages.net/up/22/42/refj.png" />
</div>
<ul class="nav-links" id="nav-links" >
<li *ngFor="let item of menuSidebar" #itemEl routerLinkActive="active">
<div *ngIf="item.sub_menu.length == 0" class="dropdown-title">
<a [routerLink]="[item.link]">
<i [class]="item.icon"></i>
<span class="link_name">{{item.link_name}}</span>
</a>
</div>
<div *ngIf="item.sub_menu.length > 0" class="dropdown-title" (click)="showSubmenu(itemEl)">
<a>
<i [class]="item.icon"></i>
<span class="link_name">{{item.link_name}}</span>
</a>
<i class='bx bxs-chevron-down arrow'></i>
</div>
<ul class="sub-menu" [class.blank]="item.sub_menu.length == 0">
<li><a class="link_name">{{item.link_name}}</a></li>
<li *ngFor="let item_sub of item.sub_menu" routerLinkActive="active">
<a [routerLink]="[item_sub.link]">{{item_sub.link_name}}</a>
</li>
</ul>
</li>
</ul>
</div>
CSS
/* Sidebar */
.sidebar {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 260px;
background: white;
z-index: 100;
transition: all 0.5s ease;
}
.sidebar.sidebar-close {
width: 60px;
}
.sidebar .logo-details{
width: 100%;
padding: 10px 10px 10px 10px;
}
.sidebar .logo-details img{
height: 50px;
width: 80%;
display: block;
margin: 0 auto;
}
.sidebar.sidebar-close .logo-details img {
width: 37px;
height: 50px;
transform: scale(1.2) translateX(-3px);
}
.sidebar .nav-links {
height: 100%;
width: 260px;
padding-bottom: 150px;
overflow: auto;
}
.sidebar .nav-links::-webkit-scrollbar {
display: none;
}
.sidebar .nav-links li {
list-style: none;
}
.sidebar .nav-links > li {
position: relative;
width: fit-content;
}
.sidebar .nav-links li:hover {
background: #ffa726;
}
.sidebar .nav-links li.active {
background-image: linear-gradient(to right, #ffa726, #ff5722);
}
/* Dropdown Title */
.sidebar .nav-links .dropdown-title {
width: 260px;
overflow: hidden;
transition: all 0.52s ease;
/* */
display: flex;
align-items: center;
justify-content: space-between;
position: relative;
}
.sidebar.sidebar-close .nav-links .dropdown-title {
width: 60px;
}
.sidebar .nav-links li i {
height: 50px;
min-width: 60px;
text-align: center;
line-height: 50px;
color: #ffa726;
font-size: 20px;
cursor: pointer;
transition: all 0.3s ease;
}
.sidebar .nav-links li:hover i,
.sidebar .nav-links li.active i {
color: white;
}
.sidebar .nav-links li.showMenu i.arrow {
transform: rotate(-180deg);
}
/* a Tag */
.sidebar .nav-links li a {
display: flex;
align-items: center;
text-decoration: none;
width: 100%;
}
/* Link Name */
.sidebar .nav-links li a .link_name {
font-size: 16px;
font-weight: 600;
color: #ffa726;
transition: all 0.4s ease;
}
.sidebar .nav-links li:hover a .link_name,
.sidebar .nav-links li.active a .link_name {
color: white;
}
.sidebar.sidebar-close .nav-links li a .link_name {
pointer-events: none;
}
/* Sub Menu */
.sidebar .nav-links li .sub-menu {
padding: 6px 6px 14px 70px;
/* margin-top: -10px; */
background: white;
display: none;
transition: all 0.4s ease;
}
.sidebar .nav-links li.showMenu .sub-menu {
display: block;
}
.sidebar .nav-links li .sub-menu a {
color: #ffa726;
font-size: 15px;
padding: 7px 0;
white-space: nowrap;
transition: all 0.3s ease;
}
.sidebar .nav-links li .sub-menu li {
padding-left: 10px;
}
.sidebar .nav-links li .sub-menu li:hover a,
.sidebar .nav-links li .sub-menu li.active a {
color: white;
}
.sidebar.sidebar-close .nav-links li .sub-menu {
position: absolute;
left: 100%;
top: -10px;
margin-top: 0;
padding: 0;
border-radius: 0 6px 6px 0;
opacity: 0;
display: block;
pointer-events: none;
transition: 0s;
overflow: hidden;
}
.sidebar.sidebar-close .nav-links li .sub-menu li {
padding: 6px 15px;
width: 200px;
}
.sidebar.sidebar-close .nav-links li:hover .sub-menu {
top: 0;
opacity: 1;
pointer-events: auto;
transition: all 0.4s ease;
}
.sidebar .nav-links li .sub-menu .link_name {
display: none;
}
.sidebar.sidebar-close .nav-links li .sub-menu .link_name {
font-size: 16px;
font-weight: 600;
/* opacity: 1; */
display: block;
}
/* li:first-child contain .link_name */
.sidebar.sidebar-close .nav-links li .sub-menu li:first-child {
background: white;
pointer-events: none;
}
.sidebar.sidebar-close .nav-links li .sub-menu li:first-child:hover .link_name,
.sidebar.sidebar-close .nav-links li .sub-menu li:first-child.active .link_name {
color: #ffa726;
}
.sidebar .nav-links li .sub-menu.blank {
pointer-events: auto;
/* padding: 3px 20px 6px 16px; */
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links li:hover .sub-menu.blank,
.sidebar .nav-links li.active .sub-menu.blank {
top: 50%;
transform: translateY(-50%);
}
.sidebar.sidebar-close ~ .home-section {
left: 60px;
width: calc(100% - 60px);
}

Your ul.sub_menu tag has a padding of 70px on the left.
At the moment you have this CSS affecting it:
.sidebar .nav-links li .sub-menu {
padding: 6px 6px 14px 70px;
background: white;
display: none;
transition: all 0.4s ease;
}
If you just add a different higher priority CSS declaration that tells it to have a different padding on the sub menu, it should work.
Here is what it looks like with a 15px padding on the left:
Also, I do see a CSS declaration that tells all ul tags to have a padding of 0. However, this is a lower priority than the mentioned code and gets overruled.

You have a 70px left padding value in the element .sidebar .nav-links li .sub-menu, which is your <ul> element. This is being generated by this shorthand line of code for the padding values:
padding: 6px 6px 14px 70px;
You need to remove this 70px value and then just tweak the padding-left value of .sidebar .nav-links li .sub-menu li which is currently set to 10px;

Related

the background of the submenu does not take up all the space

In my sidebar, when I hover over a submenu (portfolio or contact)
I would like the red background to take up the entire background of the cell.
Do you know how I could create this?
I think the problem is here? But I don't see what priority I should add?
.sidebar .nav-links li:hover {
background: red;
}
Thanks a lot
Here is a demonstration via Stackblitz
HTML
<ul class="nav-links" id="nav-links" >
<li *ngFor="let item of menuSidebar" #itemEl >
<div *ngIf="item.sub_menu.length > 0" class="dropdown-title" (click)="showSubmenu(itemEl)">
<a>
<i [class]="item.icon"></i>
<span class="link_name">{{item.link_name}}</span>
</a>
<i class='bx bxs-chevron-down arrow'></i>
</div>
<ul class="sub-menu" [class.blank]="item.sub_menu.length == 0">
<li><a class="link_name">{{item.link_name}}</a></li>
<li *ngFor="let item_sub of item.sub_menu" routerLinkActive="active">
<a [routerLink]="[item_sub.link]">{{item_sub.link_name}}</a>
</li>
</ul>
</li>
</ul>
CSS
/* Sidebar */
.sidebar {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 260px;
background: white;
z-index: 100;
transition: all 0.5s ease;
}
.sidebar.sidebar-close {
width: 60px;
}
.sidebar .logo-details{
width: 100%;
padding: 10px 10px 10px 10px;
}
.sidebar .logo-details img{
height: 50px;
width: 80%;
display: block;
margin: 0 auto;
}
.sidebar.sidebar-close .logo-details img {
width: 37px;
height: 50px;
transform: scale(1.2) translateX(-3px);
}
.sidebar .nav-links {
height: 100%;
width: 260px;
padding-bottom: 150px;
overflow: auto;
}
.sidebar .nav-links::-webkit-scrollbar {
display: none;
}
.sidebar .nav-links li {
list-style: none;
}
.sidebar .nav-links > li {
position: relative;
width: fit-content;
}
.sidebar .nav-links li:hover {
background: red;
}
/* Dropdown Title */
.sidebar .nav-links .dropdown-title {
width: 260px;
overflow: hidden;
transition: all 0.52s ease;
display: flex;
align-items: center;
justify-content: space-between;
position: relative;
}
.sidebar.sidebar-close .nav-links .dropdown-title {
width: 60px;
}
.sidebar .nav-links li i {
height: 50px;
min-width: 60px;
text-align: center;
line-height: 50px;
color: #ffa726;
font-size: 20px;
cursor: pointer;
transition: all 0.3s ease;
}
.sidebar .nav-links li:hover i,
.sidebar .nav-links li.active i {
color: white;
}
.sidebar .nav-links li.showMenu i.arrow {
transform: rotate(-180deg);
}
/* a Tag */
.sidebar .nav-links li a {
display: flex;
align-items: center;
text-decoration: none;
width: 100%;
}
/* Link Name */
.sidebar .nav-links li a .link_name {
font-size: 16px;
font-weight: 600;
color: #ffa726;
transition: all 0.4s ease;
}
.sidebar .nav-links li:hover a .link_name,
.sidebar .nav-links li.active a .link_name {
color: white;
}
.sidebar.sidebar-close .nav-links li a .link_name {
pointer-events: none;
}
/* Sub Menu */
.sidebar .nav-links li .sub-menu {
padding: 6px 6px 14px 50px;
background: #239CD3;
display: none;
transition: all 0.4s ease;
}
.sidebar .nav-links li.showMenu .sub-menu {
display: block;
}
.sidebar .nav-links li .sub-menu a {
color: #ffa726;
font-size: 15px;
padding: 7px 0;
white-space: nowrap;
transition: all 0.3s ease;
}
.sidebar .nav-links li .sub-menu li {
padding-left: 10px;
}
.sidebar .nav-links li .sub-menu li:hover a,
.sidebar .nav-links li .sub-menu li.active a {
color: black;
}
.sidebar.sidebar-close .nav-links li .sub-menu {
position: absolute;
left: 100%;
top: -10px;
margin-top: 0;
padding: 0;
border-radius: 0 6px 6px 0;
opacity: 0;
display: block;
pointer-events: none;
transition: 0s;
overflow: hidden;
}
.sidebar.sidebar-close .nav-links li .sub-menu li {
padding: 6px 15px;
width: 200px;
}
.sidebar.sidebar-close .nav-links li:hover .sub-menu {
top: 0;
opacity: 1;
pointer-events: auto;
transition: all 0.4s ease;
}
.sidebar .nav-links li .sub-menu .link_name {
display: none;
}
.sidebar.sidebar-close .nav-links li .sub-menu .link_name {
font-size: 16px;
font-weight: 600;
display: block;
}
.sidebar.sidebar-close .nav-links li .sub-menu li:first-child {
background: white;
pointer-events: none;
}
.sidebar .nav-links li .sub-menu.blank {
pointer-events: auto;
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links li:hover .sub-menu.blank,
.sidebar .nav-links li.active .sub-menu.blank {
top: 50%;
transform: translateY(-50%);
}
.sidebar.sidebar-close ~ .home-section {
left: 60px;
width: calc(100% - 60px);
}
Yes, the behaviour stems from the parent .sub-menu padding. You change background color of the child li element that is pushed away by the padding.
You can remove the padding from .sub-menu container and add it to your list items accordingly (if it's required by design):
.sidebar .nav-links li .sub-menu li:nth-child(2) {
padding: 6px 6px 0 50px;
}
.sidebar .nav-links li .sub-menu li:last-child {
padding: 0 6px 14px 50px;
}
It seems like you have a padding on your .sub-menu class. Removing it should solve your problem:
.sidebar .nav-links li .sub-menu {
background: #239CD3;
display: none;
transition: all 0.4s ease;
}
Check out the box model to better understand the behaviour of padding.

How to force a left alignment ( menu )?

Actually, I will want to align the titles on the left.
I know the problem may be this line, but I don't know what properties I should use to fix my problem? :-S
.sidebar .nav-links li a {
display: flex;
justify-content: space-between;
text-decoration: none;
transition: all 0.4s ease;
border-bottom: 1px solid #ccc;
padding: 13px 0;
}
On the other hand, the icons are correctly positioned.
CSS
.sidebar .nav-links {
margin-top: 10px;
}
.sidebar .nav-links li {
position: relative;
list-style: none;
}
.sidebar .nav-links li a {
display: flex;
justify-content: space-between;
text-decoration: none;
transition: all 0.4s ease;
border-bottom: 1px solid #ccc;
padding: 13px 0;
}
.sidebar .nav-links li a.active {
background: #081D45;
}
.sidebar .nav-links li a:hover {
background: #081D45;
}
.sidebar .nav-links li i {
min-width: 60px;
text-align: center;
font-size: 18px;
color: #fff;
}
.sidebar .nav-links .item {
text-transform: uppercase;
}
.sidebar .nav-links li i.fa-chevron-down {
right: 1rem;
left: auto;
}
.sidebar .nav-links li.active i.fa-chevron-down {
transform: rotate(180deg);
}
.sidebar .nav-links li.active i {
color: white;
}
.sidebar .nav-links li a .links_name {
color: #fff;
font-size: 15px;
font-weight: 400;
white-space: nowrap;
}
HTML
<ul class="nav-links">
<li *ngFor="let menu of menus; let i = index" [class.active]="menu.active">
<ng-container>
<a class="item" (click)="selectMenu(menu)">
<i [class]="menu.iconClass"></i>
<span class="links_name">{{ menu.name }}</span>
<i class="fa fa-chevron-down"></i>
</a>
<ul
class="submenu"
#submenu
[ngStyle]="{ 'height': menu.active ? submenu.scrollHeight + 'px' : 0 + 'px' } "
>
<li *ngFor="let submenu of menu.submenu">
<a routerLink="{{ submenu.url }} "
><span class="links_subname">{{ submenu.name }}</span>
</a>
</li>
</ul>
</ng-container>
</li>
</ul>
Here is a reproduction => Stackblitz.
Thank you in advance for your time.
you can try this.
.sidebar .nav-links li a {
display: flex;
justify-content: start;
text-decoration: none;
transition: all 0.4s ease;
border-bottom: 1px solid #ccc;
padding: 13px 0;
}
.sidebar .nav-links li i.fa-chevron-down {
right: 0;
position: absolute;
}
.sidebar .nav-links li a {
display: flex;
justify-content: start;
text-decoration: none;
transition: all 0.4s ease;
border-bottom: 1px solid #ccc;
padding: 13px 0;
}
a.item i.fa-chevron-down {
position: absolute;
min-width: 30px;
right: 4px;
}

horizontal scrollbar showing even when overflow is hidden

I'm running into a problem in my website, where an horizontal scrollbar is always showing even when i add overflow-x: hidden to the body, html elements. Instead of hiding the scrollbar, another scrollbar is added vertically and now i have two vertical scrollbars!
This happened because i have a centered navigation and add to set a child div of that same navigation, to 100% of the viewport width. Checked the developer tools in chrome and that div is going some pixels to the right.
Anyway, since overflow didn't work, i tried to change the values of the calc() function to subtract those pixels but the horizontal scrollbar is still there.
Here is my code:
<div id="container">
<ul class="nav">
<li>home</li>
<li>
destinations
<div>
<div class="nav-column">
</div>
<div class="nav-column">
</div>
<div class="nav-column">
</div>
<div class="nav-column">
</div>
<div class="nav-column">
</div>
</div>
</li>
<li>about</li>
<li>contact</li>
</ul>
</div>
And the css:
body,html {
background-color: white;
border: 0;
outline: 0;
margin: 0;
padding: 0;
max-width: 100%;
overflow-x: hidden;
}
#container {
display: block;
margin: 0 auto;
text-align: center;
position: relative;
width: 100%;
}
.nav {
cursor: default;
display: inline-block;
height: 125px;
position: relative;
top: 50px;
width: auto;
-ms-flex-pack: center;
-ms-display: -ms-flexbox;
}
.nav,
.nav a,
.nav ul,
.nav li,
.nav div {
border: none;
padding: 0;
margin: 0;
outline: none;
}
.nav a {
text-decoration: none;
}
.nav li {
list-style: none;
}
.nav > li {
display: block;
float: left;
}
.nav > li > a {
display: block;
color: black;
font-family: 'Oswald', sans-serif;
font-size: 1.2em;
font-weight: 500;
text-transform: uppercase;
height: 30px;
padding: 0 20px;
position: relative;
z-index: 510;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
-ms-transition: all .3s ease;
transition: all .3s ease;
}
.nav li:hover a {
background: black;
color: white;
}
.nav > li > div {
border: 1px solid black;
display: inline-block;
color: black;
position: absolute;
top: 30px;
left: calc(-50vw + 50%);
width: 100vw;
opacity: 0;
overflow: hidden;
visibility: hidden;
background: white;
z-index: 500;
-webkit-transition: all .3s ease .5s;
-moz-transition: all .3s ease .5s;
-o-transition: all .3s ease .5s;
-ms-transition: all .3s ease .5s;
transition: all .3s ease .5s;
}
.nav li:hover > div {
opacity: .7;
visibility: visible ;
overflow: hidden;
}
.nav .nav-column {
background-color: white;
float: left;
text-align: left;
top: -30px;
padding: 2%;
position: relative;
width: 15%;
}
.nav .nav-column h3 {
color: #d1a559;
font-family: Orator Std, IrisUPC, sans-serif;
font-weight: 900;
margin: 20px 0 10px 0;
text-decoration: underline ;
}
.nav .nav-column li {
padding-left: 0;
font-family: Palatino linotype, Rockwell;
}
.nav .nav-column li a {
background: white;
color: black;
display: block;
}
.nav .nav-column li a:hover {
background: #d1a559;
color: white;
-webkit-transition: all .1s ease;
-moz-transition: all .1s ease;
-o-transition: all .1s ease;
-ms-transition: all .1s ease;
transition: all .1s ease;
}
#media (max-width:1420px) {
.Thumbnails {
float: none;
}
}
#media (max-width: 950px) {
.nav li:hover > div {
background-color: white;
opacity: 1;
}
.nav .nav-column {
position: relative;
width: 20%;
}
.nav .nav-column li {
list-style: none;
}
}
#media (max-width: 700px) {
.nav li:hover > div {
background-color: white;
left: 0;
opacity: 1;
width: 100%;
}
.nav .nav-column {
float: none;
}
}
.colAbout {
display: block;
float: none;
}
.span_1_of_3 {
width: 70%;
}
#media (max-width: 530px) {
.nav {
display: none;
text-align: left;
height: 150px;
top: 0;
padding: 0;
margin: 0;
position: relative;
z-index: 999;
}
.nav li {
float: none;
left: 0;
}
.nav li:hover > div {
opacity: 1;
top: 113px;
}
.nav > li > a {
border-right: none;
display: block;
left: 0;
}
/*Div contendo responsive button*/
#menu {
border: 1px solid black;
color: black;
cursor: pointer;
display: block;
font-size: 1.3em;
left: 0;
margin: 5%;
position: relative;
text-align: center;
z-index: 540;
width: 1.4em;
}
#container {
left: 0;
display: block;
padding: 0;
position: relative;
width: 100%;
}
ul {
width: 100%;
list-style: none;
}
}
#media (min-width: 530px) {
#menu {
display: none;
}
}
And a fiddle example
If you just want to hide the scrollbar:
#container {
overflow: hidden!important;
}
I encountered the same issue. I still don't know the root cause, but setting overflow to "-moz-hidden-unscrollable" seems to hide the scrollbar.
.container {
overflow: -moz-hidden-unscrollable
}
I have checked your CSS. To prevent the scrollbar from being displayed, you should comment out two CSS properties: position: relative; top: 34px;
.nav {
cursor: default;
display: inline-block;
height: 125px;
width: auto;
-ms-flex-pack: center;
-ms-display: -ms-flexbox;
}

Nav Menu items Underline effect

I'm trying to have navigation menu items have underline effect when hovering. This is my current style.css code for the navigation menu.
What should I add to make it look something like this? Example: http://www.templatemonster.com/demo/54038.html .
This is my current nav bar code.
.navbar-nav .open .dropdown-menu{
display:block !important;
}
.navbar-default .navbar-nav > li > a {
color: #333;
border-bottom: 1px solid transparent;
padding: 0;
margin: 14px;
Try this..
HTML:
<ul>
<li>About</li>
</ul>
CSS:
body,html {
margin: 0;
}
ul {
margin: 150px auto 0;
padding: 0;
list-style: none;
display: table;
width: 600px;
text-align: center;
}
li {
display: table-cell;
position: relative;
padding: 15px 0;
}
a {
color: #000;
text-transform: uppercase;
text-decoration: none;
letter-spacing: 0.15em;
display: inline-block;
padding: 15px 20px;
position: relative;
}
a:after {
background: none repeat scroll 0 0 transparent;
bottom: 0;
content: "";
display: block;
height: 2px;
left: 50%;
position: absolute;
background: #000;
transition: width 0.3s ease 0s, left 0.3s ease 0s;
width: 0;
}
a:hover:after {
width: 100%;
left: 0;
}
https://jsfiddle.net/y4hc9Lbv/

CSS Menu Transition

JSFiddle: http://jsfiddle.net/x6bM3/
If you hover over the products link you will see i have created a drop down effect, but what im trying to do is give it a nice transition instead of it just appearing.
I have tried using :hover with the css transitions on various parts of the menu, but after researching it i realised the animation wont work with display: none; on it. Please help,
Thanks in advance,
Adam
CSS:
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
list-style: none;
position: relative;
display: inline-table;
margin-top: 23px;
padding: 0;
float: left;
}
nav ul:after {
content:"";
display: block;
}
nav ul li {
float: left;
height: 50px;
width: auto;
padding: 5px;
margin-left: 22px;
}
nav ul li a {
display: block;
text-decoration: none;
}
nav ul ul {
background: #363c43;
border-radius: 3px;
border: 1px solid #2e363f;
padding: 7px;
position: absolute;
font-size: 0.9em;
}
nav ul ul:before {
content:'';
display:block;
width:0;
height:0;
position:absolute;
border-right: 7px solid transparent;
border-left: 7px solid transparent;
border-bottom:10px solid #363c43;
top:-8px;
left: 30px;
}
nav ul ul li {
height: 30px;
float: none;
position: relative;
padding: 0px 0px 5px 0px;
margin: 0px;
}
/* Other base styles */
* {
font-family: arial;
}
a:link, a:visited {
color: #979797;
font-size: 1.145em;
/* 18px */
text-decoration: none;
font-weight: lighter;
-webkit-transition: all .25s linear;
transition: color .25s linear;
}
a:hover {
color: #c4c1c1;
font-size: 1.145em;
/* 22px */
text-decoration: none;
}
HTML:
<nav>
<ul class="menu">
<li>home
</li>
<li>products
<ul>
<li>product 1
</li>
<li>product 2
</li>
</ul>
</li>
<li>solutions
</li>
</ul>
</nav>
I can explain in detail, but this person does a great job: https://stackoverflow.com/a/3332179/363605
nav ul ul {
display: block;
-webkit-transition: opacity 1s ease-in;
-moz-transition: opacity 1s ease-in;
-o-transition: opacity 1s ease-in;
transition: opacity 1s ease-in;
opacity: 0;
height: 0;
overflow: hidden;
}
nav ul li:hover > ul {
height: auto;
opacity: 1;
}
http://jsfiddle.net/pYhrk/

Resources