CSS ease-in-out transition not working properly - html

I am using the CSS transition ease-in-out on a navigation bar for mouse hover.
However the transition only eases in when the mouse cursor hovers, and snaps back immediately after the cursor leaves the hyperlink area, it does not ease out smoothly.
This is the CSS I've used:
nav {
position: fixed;
z-index: 1000;
top: 0;
bottom: 0;
width: 200px;
background-color: #036;
}
nav ul {
list-style: none;
margin-top: 15px;
}
nav ul li a {
text-decoration: none;
display: block;
text-align: center;
color: #fff;
padding: 10px 0;
}
.nav-logo {
margin-left: 20px;
background-color: #cacaca;
}
.nav-logo:hover {
transform: scale(1.1);
transition: all 1s ease-in-out;
}
nav ul li a:hover {
background-color: gold;
color: black;
border-radius: 10px;
transform: scale(1.1);
transition: .3s ease-in-out;
-moz-transition: all 1s ease-in-out;
-ms-transform: scale(1.1);
-webkit-transform: scale(1.1);
}

You need to take the transition styles:
transition: .3s ease-in-out;
-moz-transition: all 1s ease-in-out;
-ms-transform: scale(1.1);
-webkit-transform: scale(1.1);
And remove them from the nav ul li a:hover and add them to the actual element nav ul li a
Whilst they remain on the hover, you are essentially removing the transition when not hovered, therefore the transition does not apply after you leave the hover state.

You need to add the transitions on the root element, not on the hover state.
nav {
background-color: yellow;
position: relative;
overflow: auto;
transition: background-color .3s ease-in-out;
}
nav:hover {
background-color: pink;
}
http://codepen.io/mrshannonyoung/pen/BLzpNz

Related

CSS Animation on Menu item is not working when hovering

I wanted to add a hover effect to my menu item, so when hovered, an line would be transitioning under it, and the line would expand from the middle out. I have included links two 2 gifs (one showing the intended animation and one showing the current result.
The structure is as follows
#main-nav .navbar-nav li:hover .top_level::after {
opacity: 1;
-webkit-transform: scaleX(1);
transform: scaleX(1);
width: calc(100%);
}
#main-nav .navbar-nav li:hover .top_level::after {
content: "";
background-color: #000;
display: block;
height: 2px;
opacity: 0;
bottom: 28px;
position: absolute;
right: 0;
left: 0;
margin: 0 auto;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: opacity 0.3s ease 0s, -webkit-transform 0.3s ease 0s;
transition: opacity 0.3s ease 0s, -webkit-transform 0.3s ease 0s;
transition: opacity 0.3s ease 0s, transform 0.3s ease 0s;
transition: opacity 0.3s ease 0s, transform 0.3s ease 0s, -webkit-transform 0.3s ease 0s !important;
width: calc(100%);
}
.navbar-nav li .top_level {
font-family: "Brandon Bold",Helvetica,Arial,sans-serif !important;
text-transform: uppercase;
font-size: 11px !important;
letter-spacing: 1.25px !important;
line-height: 28px;
color: #000;
padding: 25px 0px !important;
display: inline-block;
border-bottom: 2px solid transparent;
transition: border-color .25s ease-in-out;
position: relative;
text-decoration: none;
}
ul#main-nav {
text-align: left;
}
ul#main-nav {
padding-left: 20px;
}
ul#main-nav {
list-style: none;
text-align: left;
margin-bottom: 0;
width: 100%;
}
ul#main-nav li {
display: inline-block;
vertical-align: middle;
}
.navbar-nav li {
padding: 0 25px;
}
<ul id="main-nav">
<div class="navbar-nav">
<li><a class="top_level" href="/">Cuffs</a></li>
</div>
</ul>
The current result:
https://imgur.com/a/A8nmeQd
The intended result:
https://imgur.com/a/d9JyyhM
How can it be, that the animation doesn't load?
Thank you. :)
The problem is only the second selector (the initial status), which should be #main-nav .navbar-nav li .top_level::after instead of #main-nav .navbar-nav li:hover .top_level::after
Remove the :hover in there and it will work, as it does in the snippet below.
#main-nav .navbar-nav li:hover .top_level::after {
opacity: 1;
-webkit-transform: scaleX(1);
transform: scaleX(1);
width: calc(100%);
}
#main-nav .navbar-nav li .top_level::after {
content: "";
background-color: #000;
display: block;
height: 2px;
opacity: 0;
bottom: 28px;
position: absolute;
right: 0;
left: 0;
margin: 0 auto;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: opacity 0.3s ease 0s, -webkit-transform 0.3s ease 0s;
transition: opacity 0.3s ease 0s, -webkit-transform 0.3s ease 0s;
transition: opacity 0.3s ease 0s, transform 0.3s ease 0s;
transition: opacity 0.3s ease 0s, transform 0.3s ease 0s, -webkit-transform 0.3s ease 0s !important;
width: calc(100%);
}
.navbar-nav li .top_level {
font-family: "Brandon Bold",Helvetica,Arial,sans-serif !important;
text-transform: uppercase;
font-size: 11px !important;
letter-spacing: 1.25px !important;
line-height: 28px;
color: #000;
padding: 25px 0px !important;
display: inline-block;
border-bottom: 2px solid transparent;
transition: border-color .25s ease-in-out;
position: relative;
text-decoration: none;
}
ul#main-nav {
text-align: left;
}
ul#main-nav {
padding-left: 20px;
}
ul#main-nav {
list-style: none;
text-align: left;
margin-bottom: 0;
width: 100%;
}
ul#main-nav li {
display: inline-block;
vertical-align: middle;
}
.navbar-nav li {
padding: 0 25px;
}
<ul id="main-nav">
<div class="navbar-nav">
<li><a class="top_level" href="/">Cuffs</a></li>
</div>
</ul>

Sizing sliding underline

I want to make the sliding underline to run from left to right when i hover, and also set up the width of the line from the 1st letter to the last, and not bigger. How can i do that?
.nav-bar a:hover {
color: #000;
}
.nav-bar a:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0;
left: 0;
background-color: #000;
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.nav-bar a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
<div class="nav-bar">
<ul>
<li>RETROSPECTIVE SHOW /2006/</li>
<li>TEXTS</li>
<li>BIBLOGRAPHY</li>
</ul>
</div>
You can use display: inline-block; to keep the fixed width. And for underlining you can use pseudo-classes like :before and :after.
Have a look at the snippet below:
/* LEFT TO RIGHT */
.sliding-left-to-right {
display: inline-block;
margin: 0;
}
.sliding-left-to-right:after {
content: '';
display: block;
height: 3px;
width: 0;
background: transparent;
transition: width .5s ease, background-color .5s ease;
}
.sliding-left-to-right:hover:after {
width: 100%;
background: blue;
}
/* LAYOUT STYLING */
body {
margin: 20px;
}
a {
text-decoration: none;
font-size: 20px;
font-weight: bold;
color: blue;
}
a:hover {
color: blue;
text-decoration: none;
cursor: pointer;
}
<a class="sliding-left-to-right">Underline – Left to Right</a>
Hope this helps!

add bottom line to the anchor using after pseudo classes in css

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>

Making navigation overlay disappear when pages clicked

Im using a CSS navigation overlay menu, code below
When you click on the navigation menu and select which page you want to go to the overlay stays and does not disappear..
If i link it to another html page it works fine, but as i have all my pages on one page i'm linking it through href to a div like (href="#about")
Any idea how i can make the overlay menu hide once you click on your navigation pages?
Any help much appreciated, thank you
<nav id="menu">
<input type="checkbox" id="toggle-nav"/>
<label id="toggle-nav-label" for="toggle-nav"></label>
<div class="box">
<ul>
<li>About</li>
<li>Services</li>
<li>Work</li>
<li>Contact</li>
</ul>
</div>
</nav>
a { text-decoration: none; }
a:hover { text-decoration: underline; }
li { list-style: none; }
#menu .box {
position: fixed;
text-align: center;
overflow: hidden;
z-index: -1;
opacity: 0;
width: 100%;
height: 100%;
left: 0px;
top: 0px;
background: black;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#menu ul {
position: relative;
top: 20%;
-webkit-transform: scale(2);
-moz-transform: scale(2);
-ms-transform: scale(2);
transform: scale(2);
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#menu li {
margin: 60px;
}
#menu li a {
border-radius: 3px;
padding: 15px;
border: 1px solid transparent;
text-decoration: none;
font-family: 'Montserrat', sans-serif;
font-size: 18px;
color: #fff;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
#menu li a:hover { border-color: #fff; }
#menu li a i {
margin-right: 5px;
font-size: 24px;
}
#toggle-nav-label {
color: black;
text-align: center;
line-height: 30px;
font-size: 30px;
display: block;
cursor: pointer;
position: relative;
z-index: 500;
width: 30px;
height: 30px;
border-radius: 5px;
}
#toggle-nav { display: none; }
#toggle-nav:checked ~ .box {
opacity: 1;
z-index: 400;
}
#toggle-nav:checked ~ .box ul {
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
#toggle-nav:checked ~ #toggle-nav-label {
color: white;
position: fixed;
}
The easiest answer is to simply uncheck the checkbox using javascript ... but that kinda defeats the purpose of a checkbox hack doesn't it. I can't think of another way other than to simply make the user click the label again to close the menu. Kinda ruins the effect you're going for though. In case nothing better comes up here is a quick javascript solution:
window.onload = function() {
// Add a listener for any clicks on the menu
document.getElementById('menu').addEventListener('click', function(edit) {
var targetName = event.target.tagName;
// Make sure that the element being clicked is a link or an icon
if (targetName !== 'A' && targetName !== 'I') {
return;
}
// Uncheck the checkbox
document.getElementById('toggle-nav').checked = false;
});
}
And a codepen. If you want to allow the user to close the menu by clicking anywhere you could add && targetName !== 'DIV' to the if statement. Hope it helps, or that someone comes up with a better method, because personally, I'd love to find a way to do this with just CSS.
EDIT
Fixed JS code to use targetName. Added support for icons. Fixed codepen demo to match OP demo.
EDIT 2
Found a cross browser error. Fixed for Firefox by including event in the function parameters.

I Want To Apply Delay On Mouse Out in css

I am trying to apply a delay before starting a CSS transition on mouse out event. My CSS code is below, please let me know how to apply time delay before CSS transition on mouse out starts.
I want to achieve that the menu stays stable for some time (e.g. for 3 seconds) after the user moves mouse pointer out of the menu.
.timnav li .dropdown {
width: auto;
min-width: 0px;
max-width: 230px;
height: 0;
position: absolute;
overflow: hidden;
z-index: 999;
background:rgba(255, 255, 255, 0.8);
}
.timnav li:hover .dropdown {
min-height: 60px;
max-height: 500px;
height: auto;
width: 100%;
padding: 0;
-webkit-transition: delay .5s ease-in-out;
-moz-transition: delay .5s ease-in-out;
-o-transition: delay .5s ease-in-out;
}
.timnav li .dropdown ul {
margin: 0;
margin-top:7px;
}
.timnav li .dropdown ul > li {
display: block;
width: 100%;
float: left;
text-align: left;
height: auto;
border-radius: none;
padding-bottom:2px;
}
.timnav li .dropdown .dropdown2{
display: none;
width: 100%;
float: left;
text-align: left;
height: auto;
border-radius: none;
}
.timnav li .dropdown ul > li:hover .dropdown2{
display: block;
width: 100%;
float: left;
text-align: left;
height: auto;
border-radius: none;
}
.timnav li .dropdown .dropdown2:hover {
display: block;
width: 100%;
float: left;
text-align: left;
height: auto;
border-radius: none;
}
.timnav li .dropdown .dropdown2 li a {
display: block;
padding-left:7px !important;
height:6 !important;
padding-top:8px;
background: url(../images/nav-bg.jpg) repeat; color:#fff;
}
.timnav li .dropdown ul > li a {
display: block;
line-height: 26px;
height: 22px;
padding: 10px;
background: url(../images/nav-crrent.jpg) repeat; color:#FFFFFF;
}
.timnav ul .dropdown ul li:first-child a {
border-radius: 0;
}
.timnav li .dropdown li a:hover {
background: url(../images/nav-bg.jpg) repeat; color:#000;
}
You can add a delay to a transition, the syntax is as follows:
transition: all 0.5s ease-in-out 3s;
So
transition: <property> <duration> <timing-function> <delay>;
The syntax is the same for all the prefixed versions also.
I have created a demo of this, because you need to do something a bit tricky in order to make the item appear with no delay, but delay before it goes.
http://jsfiddle.net/pgqM2/
The trick is to re-define the transition to add the 3s delay when there is no hover, but to have a 0s delay when there is a hover:
li ul {
opacity: 0;
transition: all 0.5s ease 3s;
}
li:hover ul {
opacity: 1;
transition: all 0.5s ease 0s;
}
There is a transition-delay property in CSS. Simply add this to your code, and you will get the desired effect.
transition-delay:3s;
For the purpose of shorthand transition properties, here is a picture that sums it up
So in your case it would look like this
div:hover {
-webkit-transition: .5s ease-in-out 3s;
-moz-transition: .5s ease-in-out 3s;
-o-transition: .5s ease-in-out 3s;
transition: .5s ease-in-out 3s;
color: red;
cursor: pointer;
}
<div>Hover me. There is a delay!</div>
Here is a fiddle to demonstrate
You cant use css transition when using display none, only solution with display none is js.
You can use the css3 property transition-delay to delay executing css. Click "Try it Yourself" to see an example.