I am working on a horizontal dropdown navigation menu. I am using a transition to slow it down, but I've hit a bug. If you jump too fast (before the transition completes?) from one nav item to the other, you are still shown the other dropdown menu. It's a bit hard to explain - but I've created a CodePen.
I'm sure I'm just overlooking something basic... all feedback is appreciated. Thank you in advance!
CodePen link: https://codepen.io/zp12345/pen/mQzvXr
HTML
<div class="nav-links">
<ul class="nav-primary" id="nav-primary">
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item One</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>1.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>1.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Two</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>2.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>2.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Three</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>3.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>3.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Four</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>4.1</h5>
</a>
</li>
</ul>
</li>
</ul>
</div>
SCSS
.nav-primary {
display: flex;
flex-grow: 1;
justify-content: center;
list-style-type: none;
padding-left: 0;
}
.nav-item-top .nav-item-label {
color: #383838;
font-size: 18px;
padding: 0 24px;
cursor: pointer;
}
.nav-item-top {
&:hover {
.nav-item-label {
color: #319644;
}
.nav-dropdown {
visibility: visible;
opacity: 1;
padding: 16px 0;
}
}
}
.nav-dropdown {
width: 100%;
left: 0;
position: fixed;
top: 60px;
transition: .2s;
opacity: 0;
z-index: 3;
padding: 0;
background-color: #133751;
color: #133751;
display: flex;
align-items: center;
justify-content: center;
visibility: hidden;
list-style-type: none;
.nav-dropdown-item {
transition: .2s;
padding: 12px 24px;
text-align: center;
color: #fff;
cursor: pointer!important;
}
h5 {
color: #fff;
margin: 0;
text-transform: none;
font-size: 16px;
}
}
.nav-dropdown-item {
a {
transition: all 0.2s;
text-decoration: none;
}
}
You can use transition-delay:0.2s; on hover when you show the .nav-dropdown. That will not show the dropdown when you move mouse fast.
You can test it here
Related
I'm working on a left nav. I want the red bar to appear before menu items when hovering. It works good for the Home item and its sub items but the other root items cause the red bar to span the entire width of the page, from top to bottom, when hovering.
$(document).foundation();
.vertical.dropdown.menu [href] > i {
display: block;
}
.vertical.dropdown.menu [href] {
display: block;
text-align: center;
}
.left-bar {
position: fixed;
top: 0;
left: 0;
width: 150px;
height: 100%;
color: #333;
background: #FFFFFF;
}
.left-bar .vertical.menu.nested {
padding: 0;
}
.left-bar [href] > i {
display: block;
}
.left-bar [href] {
display: block;
text-align: left;
padding: 0;
color: #333;
}
.left-bar [href]:hover {
background: #9B9B9BFF;
}
.left-bar .vertical.menu > li {
position: relative;
background: #FFFFFF;
color: #333;
border: 0;
}
.left-bar .top-level-item [href]:hover::before {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 5px;
background-color: red;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.0/css/foundation.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.1/js/foundation.min.js"></script>
<ul class="vertical dropdown menu left-bar" data-dropdown-menu>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-home zmdi-hc-3x"></i>
<span>Home</span>
</a>
<ul class="vertical menu nested">
<li><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 1</li>
<li><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 2</li>
<!-- ... -->
</ul>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-account zmdi-hc-3x"></i>
<span>Account</span>
</a>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-settings zmdi-hc-3x"></i>
<span>Settings</span>
</a>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-help-outline zmdi-hc-3x"></i>
<span>Help</span>
</a>
</li>
<!-- ... -->
</ul>
How to fix it so that the red bar only spans the height of the menu item?
I made a change in CSS, added a comment there.There was issue in CSS selector based on DOM structure
.left-bar.vertical.menu li instead of .left-bar .vertical.menu > li , I removed the space and > , so that all li are now having position relative
$(document).foundation();
.vertical.dropdown.menu [href] > i {
display: block;
}
.vertical.dropdown.menu [href] {
display: block;
text-align: center;
}
.left-bar {
position: fixed;
top: 0;
left: 0;
width: 150px;
height: 100%;
color: #333;
background: #FFFFFF;
}
.left-bar .vertical.menu.nested {
padding: 0;
}
.left-bar [href] > i {
display: block;
}
.left-bar [href] {
display: block;
text-align: left;
padding: 0;
color: #333;
}
.left-bar [href]:hover {
background: #9B9B9BFF;
}
/* I made a change here */
.left-bar.vertical.menu li {
position: relative;
background: #FFFFFF;
color: #333;
border: 0;
}
.left-bar .top-level-item [href]:hover::before {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 5px;
background-color: red;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.0/css/foundation.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.1/js/foundation.min.js"></script>
<ul class="vertical dropdown menu left-bar" data-dropdown-menu>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-home zmdi-hc-3x"></i>
<span>Home</span>
</a>
<ul class="vertical menu nested">
<li><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 1</li>
<li><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 2</li>
<!-- ... -->
</ul>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-account zmdi-hc-3x"></i>
<span>Account</span>
</a>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-settings zmdi-hc-3x"></i>
<span>Settings</span>
</a>
</li>
<li class="top-level-item">
<a href="#">
<i class="zmdi zmdi-help-outline zmdi-hc-3x"></i>
<span>Help</span>
</a>
</li>
<!-- ... -->
</ul>
I made a border left for the red; set to white initially.
I made changes:
Cut out all the CSS not needed including all the position related
stuff
Used classes instead of some [href] I consider "fragile"
Changed to specific background-color to be clear
Set a 0 border, then added the specifics for the left one
Used rem instead of px since typical browsers use a 16px= 1rem size base; and you can force if needed to support those that do not do so.
You can decide on the sub-item if you want the container to continue to have the border and do some things related to that with CSS as here: How to style the parent element when hovering a child element?
or perhaps with some simple JavaScript to help.
$(document).foundation();
.nav-item {
width: 10rem;
background-color: #FFFFFF;
text-align: center;
color: #333;
border: 0;
border-left-width: 0.25rem;
border-left-style: solid;
border-left-color: #FFFFFF;
}
.nav-item:hover {
border-left-color: #FF0000;
}
.nav-item .nav-link:hover {
background-color: #9B9B9BFF;
}
.nav-link {
color: #333333;
}
.nav-link * {
display: block;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.0/css/foundation.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.1/js/foundation.min.js"></script>
<ul class="vertical dropdown menu left-bar" data-dropdown-menu>
<li class="top-level-item nav-item">
<a class="nav-link" href="#">
<i class="zmdi zmdi-home zmdi-hc-3x"></i>
<span>Home</span>
</a>
<ul class="vertical menu nested">
<li class="nav-item"><a class="nav-link" href="#"><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 1</a></li>
<li class="nav-item"><a class="nav-link" href="#"><i class="zmdi zmdi-list zmdi-hc-3x"></i> Sub Item 2</a></li>
</ul>
</li>
<li class="top-level-item nav-item">
<a class="nav-link" href="#">
<i class="zmdi zmdi-account zmdi-hc-3x"></i>
<span>Account</span>
</a>
</li>
<li class="top-level-item nav-item">
<a class="nav-link" href="#">
<i class="zmdi zmdi-settings zmdi-hc-3x"></i>
<span>Settings</span>
</a>
</li>
<li class="top-level-item nav-item">
<a class="nav-link" href="#">
<i class="zmdi zmdi-help-outline zmdi-hc-3x"></i>
<span>Help</span>
</a>
</li>
</ul>
you have position absolute on top-level-item href before
put position relative on top-level-item instead of the li
.top-level-item {
position: relative;
}
Unable to move my GitHub icon/link to the bottom of the navbar. I'm trying to use the last-child margin-top auto however it won't work for me. is there something wrong in my code, or am I going about it the wrong way? any advice would be great. I'm new to HTML and CSS so if you see anything you would change in general please let me know.
:root {
font-size: 16px;
font-family: 'Open sans';
}
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
body {
color: white;
background-color: black;
}
body::-webkit-scrollbar {
width: 0.3rem;
}
body::-webkit-scrollbar-track {
background-color: red;
}
body::-webkit-scrollbar-thumb {
background-color: blueviolet;
}
main {
margin-left: 15rem;
padding: 1rem;
}
/****** Navbar ******/
.img-logo {
width: 15rem;
margin-top: 1rem;
}
.navbar {
position: fixed;
background-color: blueviolet;
width: 15rem;
height: 100vh;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
}
.nav-link {
display: flex;
align-items: center;
height: 5rem;
}
.nav-item:last-child {
margin-top: auto;
}
<body>
<div class="navbar">
<nav>
<img class="img-logo" src="img/Logo.png" alt="My logo">
<ul class="navbar-nav">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-house"></i>
<span class="link-text">Home</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-user"></i>
<span class="link-text">About Me</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-screwdriver-wrench"></i>
<span class="link-text">What I Do</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-folder-open"></i>
<span class="link-text">Projects</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-id-card"></i>
<span class="link-text">Contact</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-brands fa-github"></i>
<span class="link-text"></span>
</a>
</li>
</ul>
</nav>
</div>
I got it working by flexing the navbar (parent of both navbar-nav and your image):
:root {
font-size: 16px;
font-family: 'Open sans';
}
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
body {
color: white;
background-color: black;
}
body::-webkit-scrollbar {
width: 0.3rem;
}
body::-webkit-scrollbar-track {
background-color: red;
}
body::-webkit-scrollbar-thumb {
background-color: blueviolet;
}
main {
margin-left: 15rem;
padding: 1rem;
}
/****** Navbar ******/
.img-logo {
width: 15rem;
margin-top: 1rem;
order: 2;
}
nav {
display: flex;
flex-flow: column nowrap;
position: fixed;
background-color: blueviolet;
width: 15rem;
height: 100vh;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
}
.nav-link {
display: flex;
align-items: center;
height: 5rem;
}
.nav-item:last-child {
margin-top: auto;
}
<body>
<nav>
<img class="img-logo" src="img/Logo.png" alt="My logo">
<ul class="navbar-nav">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-house"></i>
<span class="link-text">Home</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-user"></i>
<span class="link-text">About Me</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-screwdriver-wrench"></i>
<span class="link-text">What I Do</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-folder-open"></i>
<span class="link-text">Projects</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-id-card"></i>
<span class="link-text">Contact</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-brands fa-github"></i>
<span class="link-text"></span>
</a>
</li>
</ul>
</nav>
You already have a flexbox for your nav items so it makes sense to just add the logo as a list item. For this example, I called it .logo. You can then take this new list item and nest the image within. Next, we'll flex this new list item and use flex-basis: 100%;. Then you can specify align-items: flex-end; for it to be at the very bottom of the navbar.
From here, you can specify margin-left: auto; for it to be aligned to the right or the opposite for it to be aligned on the left.
:root {
font-size: 16px;
font-family: 'Open sans';
}
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
body {
color: white;
background-color: black;
}
body::-webkit-scrollbar {
width: 0.3rem;
}
body::-webkit-scrollbar-track {
background-color: red;
}
body::-webkit-scrollbar-thumb {
background-color: blueviolet;
}
main {
margin-left: 15rem;
padding: 1rem;
}
/****** Navbar ******/
.img-logo {
margin-top: 1rem;
}
.navbar {
position: fixed;
background-color: blueviolet;
width: 15rem;
height: 100vh;
}
.navbar-nav {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
}
.nav-link {
display: flex;
align-items: center;
height: 5rem;
}
.nav-item:last-child {
margin-top: auto;
}
.logo {
display: flex;
flex-basis: 100%;
align-items: flex-end;
}
<body>
<div class="navbar">
<nav>
<ul class="navbar-nav">
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-house"></i>
<span class="link-text">Home</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-user"></i>
<span class="link-text">About Me</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-screwdriver-wrench"></i>
<span class="link-text">What I Do</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-folder-open"></i>
<span class="link-text">Projects</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-solid fa-id-card"></i>
<span class="link-text">Contact</span>
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
<i class="fa-brands fa-github"></i>
<span class="link-text"></span>
</a>
</li>
<li class="logo">
<img class="img-logo" src="https://dummyimage.com/75/000/fff" alt="My logo">
</li>
</ul>
</nav>
</div>
I have a header composed of navigation links to other websites, some of these links are shown through drop-down menus. With the event hover I have added an animation and style to see what you are on at every moment and that, in case of a drop-down, shows you all the options. The thing is that once the dropdown has been shown I have added the same style and animation to the internal links as to the main ones, but in the case of the animation I always have the underline in the same place instead of just below each link. Thanks in advance for your time and help. I leave you a link with an example as I have it now working with the described behavior
https://codepen.io/carlosurra/pen/YzqXjdP
my template
<div id="row">
<div class="col-xs-12">
<header>
<nav class="navbar navbar-expand-lg navbar-light header">
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav menu">
<li class="nav-item">
<a class="nav-link">PERSONAL INFO</a>
</li>
<li class="nav-item" #mouseover="animalList = true" #mouseleave="animalList = false" >
<a class="nav-link menu-link-toggle" >PERSONAL FORM</a>
<ul class='dropdown-menu' v-if="animalList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>DATA</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>FORM DATA</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >AUTOCOMPLETE</a>
</li>
</ul>
</li>
<li class="nav-item" #mouseover="serviceList = true" #mouseleave="serviceList = false">
<a class='nav-link menu-link menu-link-toggle' >SERVICES</a>
<ul class='dropdown-menu' v-if="serviceList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >LA CRÉMATION PRIVÉE</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >PERSONAL S</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>COMPANY S</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >FULL S INFO</a>
</li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link ">SHOP</a>
</li>
<li class="nav-item active">
<router-link class="nav-link" to="/devis">PRICES</router-link>
</li>
<li class="nav-item" #mouseover="contactList = true" #mouseleave="contactList = false">
<a class='menu-link nav-link menu-link-toggle' >CONTACT</a>
<ul class='dropdown-menu' v-if="contactList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>MAIL</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >PHONE</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>
</header>
</div>
</div>
my css
html, body {
background: #009050;
}
.header {
display: flex;
justify-content: center;
align-items: baseline;
}
.menu {
list-style: none;
display: flex;
align-items: center;
}
.nav-item {
padding: 25px;
position: relative;
}
.nav-link:hover {
color: white;
}
.menu-link-toggle {
cursor: pointer;
}
.dropdown-menu {
margin-top: 10px;
list-style: none;
position: absolute;
padding: 1em 1.25em 0.5em 0.75em;
background-color: white;
width: max-content;
box-shadow: 0px 14px 24px 0px rgba(0,0,0,0.21);
}
.dropdown-menu-item {
margin: 20px 0 20px 0;
}
.dropdown-menu-link {
font-size: 14px;
font-weight: bold;
color: red;
text-decoration: none;
}
.head {
font-size: 14px;
color: red;
font-weight: bold;
text-decoration: none;
}
.nav-item:before {
content: '';
position: absolute;
width: 30%;
height: 3px;
bottom: 30%;
left: 35%;
background: white;
visibility: hidden;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}
.nav-item:hover:before,
.nav-item:focus:before {
visibility: visible;
transform: scaleX(1);
}
.dropdown-menu-link:before {
content: '';
position: absolute;
width: 30%;
height: 3px;
bottom: 30%;
left: 0%;
background: #D53865;
visibility: hidden;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}
.dropdown-menu-link:hover:before,
.dropdown-menu-link:focus:before {
visibility: visible;
transform: scaleX(1);
}
.added {
display: none;
}
Please add this to your code
.dropdown-menu-link {
padding-bottom:3px;
position:relative;
}
.dropdown-menu-item {
position:relative;
}
Change the code bottom:30%; to bottom: 0px;
.dropdown-menu-link:before {
bottom: 0px;
}
Please check this codepen :
https://codepen.io/Rayeesac/pen/LYNpyEx
Add position: relative to .dropdown-menu-item and set a correct position to bottom of .dropdown-menu-item:before, let's say to 0px;
Or if you want to be relative to the link set position: relative to .dropdown-menu-link.
I have a working navigation, but I want the transition between switching dropdown menus to be smoother. Right now, there is an uncomfortable 'blinking' when you hover between the various main menu links. I know it is caused because of the transition time, but I'm not sure how to fix it. I want the transition to be seamless, as if only the dropdown items themselves are changing (not the background).
Below is my code, and here is a link to a CodePen (https://codepen.io/zp12345/pen/mQzvXr). Any help is appreciated. Thanks!
HTML
<div class="nav-links">
<ul class="nav-primary" id="nav-primary">
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item One</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>1.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>1.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Two</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>2.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>2.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Three</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>3.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>3.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Four</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>4.1</h5>
</a>
</li>
</ul>
</li>
</ul>
</div>
SCSS
.nav-primary {
display: flex;
flex-grow: 1;
justify-content: center;
list-style-type: none;
padding-left: 0;
}
.nav-item-top .nav-item-label {
color: #383838;
font-size: 18px;
padding: 0 24px;
cursor: pointer;
}
.nav-item-top {
&:hover {
.nav-item-label {
color: #319644;
}
.nav-dropdown {
visibility: visible;
opacity: 1;
padding: 16px 0;
}
}
}
.nav-dropdown {
width: 100%;
left: 0;
position: fixed;
top: 60px;
transition: .2s;
opacity: 0;
z-index: 3;
padding: 0;
background-color: #133751;
color: #133751;
display: flex;
align-items: center;
justify-content: center;
visibility: hidden;
list-style-type: none;
.nav-dropdown-item {
transition: .2s;
padding: 12px 24px;
text-align: center;
color: #fff;
cursor: pointer!important;
}
h5 {
color: #fff;
margin: 0;
text-transform: none;
font-size: 16px;
}
}
.nav-dropdown-item {
a {
transition: all 0.2s;
text-decoration: none;
}
}
In your styles you can adjust the .nav-dropdown transition property to a higher time to make it seem more smooth.
.nav-dropdown {
transition: 2s;
}
As mentioned by #mike-tung, it is about timing of the transition.
You could use an opacity effect on nav-dropdown with low transition timing. It would run smoothly.
.nav-hover:hover {
.nav-dropdown {
transition: 0.3s ease;
opacity: 1;
}
}
.nav-dropdown {
transition: 0.2s ease;
opacity: 0;
...
}
And I see an issue that when you hover out the nav bar, the dropdown is immediately hidden, making it virtually impossible for user to access it.
Thus, I'd suggest you to reduce the top attribute ov nav-dropdown, so it stays right below the NAV menu, and then set the background color only to your .nav-dropdown-item.
.nav-dropdown-item {
width: 100%;
background-color: #133751;
...
}
And giving a padding top to .nav-dropdown:
padding: 20px 0 0; // I let the 0s to not mess with your original padding: 0;
The results would be something like this:
https://codepen.io/annabranco/pen/QJYWvm?editors=1100
Hope it helps! :)
I have created a basic menu with years on the top and a circle below. When hovering over the li the font size is increased but this seems to be causing a wobble or jitter on the circle below.
How do I stop this and have smooth effect on hover? I have included my css and html in a code snippet so you can see what I am talking about.
#timeline ul {
text-align: center;
text-transform: uppercase;
margin: 0;
padding: 0;
}
ul li {
position: relative;
display: inline-block;
float: none;
width: 5%;
max-width: 140px;
padding: 25px 0;
transition: all .3s ease;
box-sizing: border-box;
text-align: center;
font-family: alternate-gothic-no-3-d,Helvetica Neue,Helvetica,Arial,sans-serif;
font-size: 20px;
}
#timeline ul .hovered, #timeline ul li:hover {
transition: all .5s;
font-size: 35px;
cursor: pointer;
padding-top: 12px;
padding-bottom: 21px;
}
#timeline ul li .indicator {
display: block;
}
#timeline ul li .title:before {
content: "";
position: absolute;
bottom: 0;
left: 50%;
width: 12px;
height: 12px;
border: 3px solid #a39688;
border-radius: 100%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
transition: all .3s ease;
}
<div id="timeline">
<ul class="timeline-list">
<li class="" data-number="1">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="2">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="hovered" data-number="3">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="4">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="5">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="6">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="7">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="8">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="9">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="10">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="11">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
</ul>
</div>
Try to made the .title absolute as i did in the code
#timeline ul {
text-align: center;
text-transform: uppercase;
margin: 0;
padding: 0;
}
span.title {
position: absolute;
width: 100%;
text-align: center;
left: 0;
bottom: 20px;
}
ul li {
position: relative;
display: inline-block;
float: none;
width: 5%;
max-width: 140px;
padding: 25px 0;
transition: all .3s ease;
box-sizing: border-box;
text-align: center;
font-family: alternate-gothic-no-3-d,Helvetica Neue,Helvetica,Arial,sans-serif;
font-size: 20px;
height: 80px;
}
#timeline ul .hovered, #timeline ul li:hover {
transition: all .5s;
font-size: 35px;
cursor: pointer;
padding-top: 12px;
padding-bottom: 21px;
}
#timeline ul li .indicator {
display: block;
}
#timeline ul li:before {
content: "";
position: absolute;
bottom: 0;
left: 50%;
width: 12px;
height: 12px;
border: 3px solid #a39688;
border-radius: 100%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
transition: all .3s ease;
}
<div id="timeline">
<ul class="timeline-list">
<li class="" data-number="1">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="2">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="hovered" data-number="3">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="4">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="5">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="6">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="7">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="8">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="9">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="10">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
<li class="" data-number="11">
<span class="indicator"></span>
<span class="title">1861</span>
</li>
</ul>
</div>
You have a few problems:
inline blocks don't like whitespace between them
add vertical-align: top; to the css of ul li
the main problem is you're trying to substitute font-size for padding. In the normal li it is 25px padding + 20px font + 25px padding, in the hover it is 12px padding + 35px font.
the solution: remove all the padding, and only add line-height: 75px to the css of ul li
Here's a working fiddle