I am working on a menu. when i hover over hamburger icon menu animation works good,but when mouse leaves it menu disappear suddenly. I want that it disappears in reverse animation.How can i do it?Please help.
https://codepen.io/sen-tanmoy/pen/NWPvLLK
HTML code
<div class="wrapper">
<nav class="navbar">
<ul>
<li class="no">
<div class="hamburger-menu-icon">
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
</div>
<ul class="dropdown" aria-label="submenu">
<li>Home</li>
<li>Projects</li>
<li>News/Awards</li>
<li>Upcoming Projects</li>
<li>About Us</li>
<li>Our Team</li>
<li>Contact Us</li>
</ul>
</li>
</ul>
</nav>
</div>
It looks like it was disappearing abruptly because you were changing the display between block and none on hover. I removed that and added a separate closing animation that plays when you're not hovering.
The problem with keeping it set to display: block; is that you can trigger the animation by hovering over the area where the menu will be, even when it's closed.
So I added another animation to scale the .dropdown div after the menu items are closed.
At this point, it looked ok except the menu would start out open and then collapse after the page loads, so I added another animation to keep it hidden until the menu items are finished collapsing.
You may want to mess with the timings a bit, but this should get you pretty close.
* {
margin: 0;
padding: 0;
}
.navbar {
width: 330px;
height: 95vh;
margin-top: 5vh;
position: fixed;
display: flex;
transition: opacity 1.5s ease;
}
.hamburger-menu-icon {
width: 55px;
height: 50px;
padding: 18px;
display: flex;
flex-direction: column;
justify-content: space-around;
cursor: pointer;
background-color: silver;
border-radius: 50%;
}
.line {
width: 100%;
height: 5px;
background-color: rgb(255, 255, 255);
transition: all 0.8s;
display: flex;
justify-content: center;
align-items: center;
}
nav a {
text-decoration: none;
font-size: 24px;
}
nav ul {
list-style: none;
margin: 0;
padding-left: 0;
margin-right: auto;
}
nav li {
color: black;
/* background: #262626; */
display: block;
padding: 10px 25px;
position: relative;
text-decoration: none;
transition-duration: 500ms;
}
.no {
background: none;
}
.dropdown {
padding-top: 20px;
width: 250px;
transform-origin: top left;
animation: lateClose 2000ms both ease;
/* transition-duration: 500ms; */
}
.same {
position: relative;
padding-bottom: 10px;
animation: initialArrival 1500ms both ease;
}
.same::after {
content: "";
width: 100%;
height: 2px;
position: absolute;
/* left: 10px; */
bottom: 0;
right: 0;
background-color: #2A324B;
transform: scaleX(0);
transition: transform 0.5s;
}
.same:hover::after {
transform: scaleX(1);
transform-origin: left;
}
nav li a {
color: inherit;
}
.no:hover .dropdown {
animation: animateOpen 1ms both ease;
}
.dropdown:hover,
.dropdown:focus {
/* background-color: #cc2a36; */
color: #fff;
cursor: pointer;
}
nav ul li ul {
position: absolute;
transition: background-color 0.5s ease-in;
margin-top: 10px;
left: 0;
display: block;
}
nav ul li:hover >ul,
nav ul li:focus >ul,
.dropdown:hover,
.dropdown:focus {
opacity: 1;
/* display: block; */
/* transition: all 1s ease; */
}
nav ul li ul li {
clear: both;
width: 100%;
animation: animateClosed 900ms both ease;
}
nav:hover ul li ul li {
clear: both;
width: 100%;
animation: animateOpen 900ms both ease;
}
nav ul li ul li:nth-of-type(1) {
transform-origin: top left;
transform: skewX(45deg) scaleY(0);
}
nav ul li ul li:nth-of-type(2) {
transform-origin: top right;
transform: skewX(-45deg) scaleY(0);
animation-delay: 150ms;
}
nav ul li ul li:nth-of-type(3) {
transform-origin: top right;
transform: skewX(45deg) scaleY(0);
animation-delay: 300ms;
}
nav ul li ul li:nth-of-type(4) {
transform-origin: top right;
transform: skewX(-45deg) scaleY(0);
animation-delay: 450ms;
}
nav ul li ul li:nth-of-type(5) {
transform-origin: top right;
transform: skewX(45deg) scaleY(0);
animation-delay: 600ms;
}
nav ul li ul li:nth-of-type(6) {
transform-origin: top right;
transform: skewX(-45deg) scaleY(0);
animation-delay: 750ms;
}
nav ul li ul li:nth-of-type(7) {
transform-origin: top right;
transform: skewX(45deg) scaleY(0);
animation-delay: 900ms;
}
#keyframes animateOpen {
0% {
transform: skewX(0deg) scaleY(0);
}
100% {
transform: skewX(0deg) scaleY(1);
}
}
#keyframes animateClosed {
0% {
transform: skewX(0deg) scaleY(1);
}
100% {
transform: skewX(0deg) scaleY(0);
}
}
#keyframes lateClose {
0% {
transform: scaleY(1);
}
99% {
transform: scaleY(1);
}
100% {
transform: scaleY(0);
}
}
#keyframes initialArrival {
0% {
opacity: 0;
}
99% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="wrapper">
<nav class="navbar">
<!-- <h2>Saffron</h2> -->
<ul>
<li class="no">
<div class="hamburger-menu-icon">
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
</div>
<ul class="dropdown" aria-label="submenu">
<li>Home</li>
<li>Projects</li>
<li>News/Awards</li>
<li>Upcoming Projects</li>
<li>About Us</li>
<li>Our Team</li>
<li>Contact Us</li>
</ul>
</li>
</ul>
</nav>
</div>
Related
I have made a burger menu for my site but the dropdown menu/ element does not go inside the menu icon. It moves the wrong way. It goes from left to right but I need it to go from right to left. I can't figure out how to make the menu move the other way. I have tried to tweak some of the tags but either it's not worked or it's broken.
nav {
position: absolute;
top: -2%;
left: 93%;
}
#menuToggle {
display: block;
position: relative;
top: 50px;
left: 50px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle a {
text-decoration: none;
color: #232323;
transition: color 0.3s ease;
}
#menuToggle a:hover {
color: tomato;
}
#menuToggle input {
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0;
z-index: 2;
-webkit-touch-callout: none;
}
#menuToggle span {
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #ffffff;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), opacity 0.55s ease;
}
#menuToggle span:first-child {
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2) {
transform-origin: 0% 100%;
}
#menuToggle input:checked~span {
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #232323;
}
#menuToggle input:checked~span:nth-last-child(3) {
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
#menuToggle input:checked~span:nth-last-child(2) {
transform: rotate(-45deg) translate(0, -1px);
}
#menu {
position: absolute;
width: 300px;
margin: -100px 0 0 -50px;
padding: 50px;
padding-top: 125px;
background: #ffffff;
list-style-type: none;
-webkit-font-smoothing: antialiased;
transform-origin: 0% 0%;
transform: translate(-100%, 0);
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0);
}
#menu li {
padding: 10px 0;
font-size: 22px;
}
#menuToggle input:checked~ul {
transform: none;
}
<nav role="navigation">
<div id="menuToggle">
<input type="checkbox" />
<span></span>
<span></span>
<span></span>
<ul id="menu">
<li>Home</li>
<li>About us</li>
<li>Rules</li>
<li>Support us</li>
</ul>
</div>
</nav>
any help is greatly appreciated, thank you
I'm using this Pure CSS hamburger menu code: https://codepen.io/Joanc/pen/XYYZdE
body
{
margin: 0;
padding: 0;
/*make it look decent enough*/
background: #232323;
color: #cdcdcd;
font-family: "Avenir Next", "Avenir", sans-serif;
overflow-x: hidden; /*needed because hiding the menu on the right side is not perfect*/
}
a
{
text-decoration: none;
color: #232323;
transition: color 0.3s ease;
}
a:hover
{
color: tomato;
}
#menuToggle
{
display: block;
position: absolute;
top: 50px;
right: 50px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle input
{
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0; /*hide this*/
z-index: 2; /*and place it over the hamburger*/
-webkit-touch-callout: none;
}
/*Just a quick hamburger*/
#menuToggle span
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
}
#menuToggle span:first-child
{
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2)
{
transform-origin: 0% 100%;
}
/*Transform all the slices of hamburger into a crossmark*/
#menuToggle input:checked ~ span
{
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #232323;
}
/*But let's hide the middle one*/
#menuToggle input:checked ~ span:nth-last-child(3)
{
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
/*Ohyeah and the last one should go the other direction*/
#menuToggle input:checked ~ span:nth-last-child(2)
{
opacity: 1;
transform: rotate(-45deg) translate(0, -1px);
}
/*Make this absolute positioned at the top left of the screen*/
#menu
{
position: absolute;
width: 300px;
margin: -100px 0 0 0;
padding: 50px;
padding-top: 125px;
right: -100px;
background: #ededed;
list-style-type: none;
-webkit-font-smoothing: antialiased;
/*to stop flickering of text in safari*/
transform-origin: 0% 0%;
transform: translate(100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li
{
padding: 10px 0;
font-size: 22px;
}
/*And let's fade it in from the left*/
#menuToggle input:checked ~ ul
{
transform: scale(1.0, 1.0);
opacity: 1;
}
<!-- Made by Erik Terwan -->
<!-- 24th of November 2015 -->
<!-- MIT License -->
<nav role='navigation'>
<div id="menuToggle">
<!--
A fake / hidden checkbox is used as click reciever,
so you can use the :checked selector on it.
-->
<input type="checkbox" />
<!--
Some spans to act as a hamburger.
They are acting like a real hamburger,
not that McDonalds stuff.
-->
<span></span>
<span></span>
<span></span>
<!--
Too bad the menu has to be inside of the button
but hey, it's pure CSS magic.
-->
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>Info</li>
<li>Contact</li>
<li>Show me more</li>
</ul>
</div>
</nav>
After endless tryouts, I find myself completely unable to set the height of the side navbar to 100% and change the width according to the screen size.
What am I missing? What cannot I see? I would extremely appreciate any kind of help.
Thank you in advance and cheers!
This is the solution:
#menu
{
position: absolute;
height: 100vh;
width: 50vw;
margin: -100px 0 0 0;
padding: 50px;
padding-top: 125px;
right: -100px;
background: #ededed;
list-style-type: none;
-webkit-font-smoothing: antialiased;
/* to stop flickering of text in safari */
transform-origin: 0% 0%;
transform: translate(100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
if you use: vh - vw instead of the % everything should work fine.
this works because it'll only fill up 100% of the height or 50% of the viewport, and not the parent.
Adding height: 100vh to your #menu css tells the container to fill 100% of the viewport height. If you change from the fixed-width of width: 300px to width: 25vw for example, your menu will only ever occupy 25% of the viewport width.
body
{
margin: 0;
padding: 0;
/*make it look decent enough*/
background: #232323;
color: #cdcdcd;
font-family: "Avenir Next", "Avenir", sans-serif;
overflow-x: hidden; /*needed because hiding the menu on the right side is not perfect*/
}
a
{
text-decoration: none;
color: #232323;
transition: color 0.3s ease;
}
a:hover
{
color: tomato;
}
#menuToggle
{
display: block;
position: absolute;
top: 50px;
right: 50px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle input
{
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0; /*hide this*/
z-index: 2; /*and place it over the hamburger*/
-webkit-touch-callout: none;
}
/*Just a quick hamburger*/
#menuToggle span
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
}
#menuToggle span:first-child
{
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2)
{
transform-origin: 0% 100%;
}
/*Transform all the slices of hamburger into a crossmark*/
#menuToggle input:checked ~ span
{
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #232323;
}
/*But let's hide the middle one*/
#menuToggle input:checked ~ span:nth-last-child(3)
{
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
/*Ohyeah and the last one should go the other direction*/
#menuToggle input:checked ~ span:nth-last-child(2)
{
opacity: 1;
transform: rotate(-45deg) translate(0, -1px);
}
/*Make this absolute positioned at the top left of the screen*/
#menu
{
position: absolute;
width: 25vw;
height: 100vh;
margin: -100px 0 0 0;
padding: 50px;
padding-top: 125px;
right: -100px;
background: #ededed;
list-style-type: none;
-webkit-font-smoothing: antialiased;
/*to stop flickering of text in safari*/
transform-origin: 0% 0%;
transform: translate(100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li
{
padding: 10px 0;
font-size: 22px;
}
/*And let's fade it in from the left*/
#menuToggle input:checked ~ ul
{
transform: scale(1.0, 1.0);
opacity: 1;
}
<!-- Made by Erik Terwan -->
<!-- 24th of November 2015 -->
<!-- MIT License -->
<nav role='navigation'>
<div id="menuToggle">
<!--
A fake / hidden checkbox is used as click reciever,
so you can use the :checked selector on it.
-->
<input type="checkbox" />
<!--
Some spans to act as a hamburger.
They are acting like a real hamburger,
not that McDonalds stuff.
-->
<span></span>
<span></span>
<span></span>
<!--
Too bad the menu has to be inside of the button
but hey, it's pure CSS magic.
-->
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>Info</li>
<li>Contact</li>
<li>Show me more</li>
</ul>
</div>
</nav>
I made a menu that appears when clicking a hamburger button with CSS and a checkbox. It works nicely so far. But now I want it to disappear when clicking elsewhere on the page, not only when clicking on the hamburger button again. How do I do that, please?
HTML:
<div class="navigatie">
<input class="nav-toggle" id="nav-toggle" type="checkbox">
<nav>
<ul>
<li>Home</li>
<li>Werkwijze</li>
<li>Over ons</li>
<li>Faq</li>
<li>Accreditatie</li>
</ul>
</nav>
<label for="nav-toggle" class="nav-toggle-label">
<span><i class="fas fa-bars"></i></span>
</label>
</div>
CSS:
.nav-toggle {
display: none;
}
nav {
position: absolute;
bottom: 100%;
left: 30%;
background-color: #f1f1f1;
width: 40%;
transform: scale(1,0);
transform-origin: bottom;
transition: transform 400ms ease-in-out;
}
nav a {
color: #65A624;
font-size: 1rem;
opacity: 0;
transition: opacity 150ms ease-in;
display: block;
}
nav a:hover:not(.active) {
background-color: #555;
color: white;
}
nav a.active {
background-color: #65A624;
color: white;
}
.nav-toggle:checked ~ nav {
transform: scale(1,1);
}
.nav-toggle:checked ~ nav a {
opacity: 1;
transition: opacity 250ms ease-in-out 250ms;
}
Greetings,
Sandra.
$(document).ready(function () {
$(document).click(function (event) {
var clickover = $(event.target);
var _opened = $(".navbar-collapse").hasClass("navbar-collapse in");
if (_opened === true && !clickover.hasClass("navbar-toggle")) {
$("button.navbar-toggle").click();
}
});
});
Check out this jsfiddle sample.
http://jsfiddle.net/52VtD/5718/
CSS Solution
If you want it purely CSS you can do the example below, I've edited a few things because your code missed some CSS and HTML to make it reproducible correctly. But the point should be clear. ;)
A overlay appears after opening, you can close the menu by clicking anywhere in the overlay (darker background)
Advice: use JavaScript
I would recommend however to make it easier and use JavaScript if that is a option.
.nav-toggle-label {
width: 3rem;
height: 3rem;
margin: 0;
display: block;
background-color: #0F0;
}
.nav-toggle {
width: 0.1rem;
height: 0.1rem;
position: absolute;
top: 0;
left: 0;
opacity: 0;
}
nav {
width: 40%;
position: absolute;
top: 0%;
left: 30%;
z-index: 110;
background-color: #f1f1f1;
transform: scale(1, 0);
transform-origin: bottom;
transition: transform 400ms ease-in-out;
}
nav a {
color: #65A624;
font-size: 1rem;
opacity: 0;
transition: opacity 150ms ease-in;
display: block;
}
nav a:hover:not(.active) {
background-color: #555;
color: white;
}
nav a.active {
background-color: #65A624;
color: white;
}
.nav-toggle:checked~.navigatie nav {
transform: scale(1, 1);
}
.nav-toggle:checked ~ .navigatie a {
opacity: 1;
transition: opacity 250ms ease-in-out 250ms;
}
.nav-toggle-close {
width: 100%;
height: 100%;
position: absolute;
top: 0%;
left: 0%;
background-color: rgba(0, 0, 0, 0.3);
display: none;
z-index: 100;
}
.nav-toggle:checked ~ .nav-toggle-close {
display: block;
}
<input class="nav-toggle" id="nav-toggle" type="checkbox">
<label for="nav-toggle" class="nav-toggle-close"></label>
<div class="navigatie">
<nav>
<ul>
<li>Home</li>
<li>Werkwijze</li>
<li>Over ons</li>
<li>Faq</li>
<li>Accreditatie</li>
</ul>
</nav>
<label for="nav-toggle" class="nav-toggle-label">
<span><i class="fas fa-bars">Menu</i></span>
</label>
</div>
I usually don't have an issue with transitions.
But, I am implementing a hamburger menu and want the ul to fade in.
Here is the code:
nav #toggle {
display: none;
}
nav #navelements {
display: none;
transition: .7s;
}
nav #navelements ul li {
line-height: 2rem;
text-align: left;
width: 100%;
}
nav #toggle:checked+#navelements {
display: block;
transition: .7s;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<nav>
<h1>
LOGO
</h1>
<label for="toggle">☰</label>
<input type="checkbox" id="toggle">
<div id="navelements">
<ul>
<li>home</li>
<li>about</li>
<li>contact</li>
</ul>
</div>
</nav>
</body>
</html>
What am I doing wrong?
transition doesn't work with display & visibility values, therefore you have to do it with the opacity:
nav #toggle {
display: none;
}
nav #navelements {
opacity: 0;
transition: opacity .5s linear;
}
nav #navelements ul li {
line-height: 2rem;
text-align: left;
width: 100%;
}
nav #toggle:checked+#navelements {
opacity: 1;
}
<nav>
<h1>
LOGO
</h1>
<label for="toggle">☰</label>
<input type="checkbox" id="toggle">
<div id="navelements">
<ul>
<li>home</li>
<li>about</li>
<li>contact</li>
</ul>
</div>
</nav>
You may try this effective hamburger menu using only css3 and html 5
body
{
margin: 0;
padding: 0;
background: #0077CC;
color: #cdcdcd;
font-family: "Avenir Next", "Avenir", sans-serif;
}
a {
text-decoration: none;
color: #232323;
transition: color 0.3s ease;
}
a:hover {
color: #0077CC;
}
#menuToggle {
display: block;
position: relative;
top: 10px;
left: 10px;
z-index: 1;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#menuToggle input
{
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0; /* hide this */
z-index: 2; /* and place it over the hamburger */
-webkit-touch-callout: none;
}
#menuToggle span {
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
-webkit-transform-origin: 4px 0px;
transform-origin: 4px 0px;
transition: background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease,
-webkit-transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease,
-webkit-transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menuToggle span:first-child {
-webkit-transform-origin: 0% 0%;
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2) {
-webkit-transform-origin: 0% 100%;
transform-origin: 0% 100%;
}
#menuToggle input:checked ~ span {
opacity: 1;
-webkit-transform: rotate(45deg) translate(-2px, -1px);
transform: rotate(45deg) translate(-2px, -1px);
background: #232323;
}
#menuToggle input:checked ~ span:nth-last-child(3) {
opacity: 0;
-webkit-transform: rotate(0deg) scale(0.2, 0.2);
transform: rotate(0deg) scale(0.2, 0.2);
}
#menuToggle input:checked ~ span:nth-last-child(2) {
-webkit-transform: rotate(-45deg) translate(0, -1px);
transform: rotate(-45deg) translate(0, -1px);
}
#menu {
position: absolute;
width: 300px;
margin: -100px 0 0 -50px;
padding: 50px;
padding-top: 125px;
height:auto;
height: 200px;
background: #ededed;
list-style-type: none;
-webkit-font-smoothing: antialiased;
/* to stop flickering of text in safari */
-webkit-transform-origin: 0% 0%;
transform-origin: 0% 0%;
-webkit-transform: translate(-100%, 0);
transform: translate(-100%, 0);
transition: -webkit-transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0), -webkit-transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li {
padding: 5px 0;
font-size: 22px;
}
#menuToggle input:checked ~ ul {
-webkit-transform: none;
transform: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav role="navigation">
<div id="menuToggle">
<!--
A hidden checkbox is used as click reciever,
so you can use the :checked selector on it.
-->
<input type="checkbox" />
<!--
Some spans to act as a hamburger.
They are acting like a real hamburger,
-->
<span></span>
<span></span>
<span></span>
<ul id="menu">
<li>home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</nav>
trying to display line on the bottom of navigation anchor with the help of before,after i try a lot to solve my problem but don't any solution about this problem. i want to add bottom line with the help of css transform and transition using after pasudo classes
<html>
<head>
<style>
body,ul,li,a,nav{
margin: 0;
padding: 0;
}
nav {
background-color: #dadada;
}
.menu-items {
list-style: none;
text-align: center;
}
.menu-items a {
float: left;
text-decoration: none;
padding:10px 10px;
color: #fff;
}
.header-menu li > a::after {
border-color: red;
border-style: solid;
position: absolute;
top: 20%;
left: 0;
width: 50%;
height: 0px;
/*background: rgba(0,0,0,0.1);*/
content: '';
opacity: 0;
-webkit-transition: opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: opacity 0.3s, -moz-transform 0.3s;
transition: opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(20px);
-moz-transform: translateY(20px);
transform: translateY(20px);
}
.header-menu li > a:hover::after {
opacity: 1;
-webkit-transform: translateY(1px);
-moz-transform: translateY(1px);
transform: translateY(1px);
}
.menu-items li {
display: inline-block;
}
</style>
</head>
<body>
<nav class="header-menu">
<ul class="menu-items">
<li>Home</li>
<li>Animal</li>
<li>Birds</li>
<li>Sports</li>
<li>Address</li>
<li>News</li>
</ul>
</nav>
</body>
</html>
Add position: relative to .header-menu li > a or to .menu-items a
relative
This keyword lays out all elements as though the element were not positioned, and then adjust the element's position, without changing
layout (and thus leaving a gap for the element where it would have
been had it not been positioned). The effect of position:relative on
table--group, table-row, table-column, table-cell, and table-caption
elements is undefined.
then change top: 50%; in .header-menu li > a::after to top: 100%;
Live DEMO
body,
ul,
li,
a,
nav {
margin: 0;
padding: 0;
}
nav {
background-color: #dadada;
}
.menu-items {
list-style: none;
text-align: center;
}
.menu-items a {
float: left;
text-decoration: none;
padding: 10px 10px;
color: #fff;
position: relative/*this will wrap pseudo elements*/
}
.header-menu li > a::after {
border-color: red;
border-style: solid;
position: absolute;
top: 100%; /*because we want it to be at the bottom of the anchor*/
left: 10px; /*10px because anchor has a padding of 10px*/
width: 50%;
height: 0px;
/*background: rgba(0,0,0,0.1);*/
content: '';
opacity: 0;
-webkit-transition: opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: opacity 0.3s, -moz-transform 0.3s;
transition: opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(20px);
-moz-transform: translateY(20px);
transform: translateY(20px);
}
.header-menu li > a:hover::after {
opacity: 1;
-webkit-transform: translateY(1px);
-moz-transform: translateY(1px);
transform: translateY(1px);
}
.menu-items li {
display: inline-block;
}
<nav class="header-menu">
<ul class="menu-items">
<li>Home
</li>
<li>Animal
</li>
<li>Birds
</li>
<li>Sports
</li>
<li>Address
</li>
<li>News
</li>
</ul>
</nav>