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.
Related
I have a question regarding the text color of my drop down menu. The drop down text color is based off of the main link text color. When I select that link it changes to the current tab color, but also changes the drop down text color. I was wondering how to make the drop down menu color independent from the main tab text color.
Here is the HTML:
<nav id="nav-wrap">
<a class="mobile-btn" href="#nav-wrap" title="Show navigation">Show navigation</a>
<a class="mobile-btn" href="#" title="Hide navigation">Hide navigation</a>
<ul id="nav" class="nav">
<li>Home</li>
<li class="current">Blog
</li>
<li><span>Resources</span>
<ul>
<li>Alcohol</li>
<li>Drugs</li>
<li>Mental Health</li>
<li>Suicide</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
</ul> <!-- end #nav -->
</nav> <!-- end #nav-wrap -->
And here is the CSS:
#nav-wrap ul, #nav-wrap li, #nav-wrap a {
margin: 0;
padding: 0;
border: none;
outline: none;
}
/* nav-wrap */
#nav-wrap {
position: relative;
font: 15px raleway-heavy, sans-serif;
text-transform: uppercase;
letter-spacing: 1.5px;
float: right;
margin-top: 32px;
margin-right: 20px;
z-index: 99999;
}
/* hide toggle button */
#nav-wrap > a.mobile-btn {
display: none;
border-radius: 3px;
}
ul#nav {
min-height: 48px;
width: auto;
/* left align the menu */
text-align: left;
}
ul#nav li {
position: relative;
list-style: none;
height: 48px;
display: inline-block;
}
/* Links */
ul#nav li a {
/* 8px padding top + 8px padding bottom + 32px line-height = 48px */
display: inline-block;
padding: 8px 11px;
line-height: 32px;
text-decoration: none;
text-align: left;
color: #ffffff;
-webkit-transition: color .2s ease-in-out;
-moz-transition: color .2s ease-in-out;
-o-transition: color .2s ease-in-out;
-ms-transition: color .2s ease-in-out;
transition: color .2s ease-in-out;
}
ul#nav li a:active { background-color: transparent !important; }
ul#nav li:hover > a,
ul#nav li.current a { color: #00b2ee; }
/* adds down arrow */
ul#nav span:after {
width: 0;
height: 0px;
border: 4px solid transparent;
border-bottom: none;
border-top-color: #00b2ee;
content: '';
vertical-align: middle;
display: inline-block;
position: relative;
right: 5px;
}
/* Sub Menu
----------------------------------------------------- */
ul#nav ul {
position: absolute;
top: 100%;
left: 0;
background: #c7c7c7;
min-width: 100%;
border-radius: 5px 5px 7px 7px;
/* for transition effects */
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity .25s ease .1s;
-moz-transition: opacity .25s ease .1s;
-o-transition: opacity .25s ease .1s;
-ms-transition: opacity .25s ease .1s;
transition: opacity .25s ease .1s;
}
/* Third level sub menu
ul#nav ul ul {
position: absolute;
top: 0;
left: 100%;
border-radius: 0 3px 3px 3px;
}
*/
ul#nav ul li {
padding: 0;
display: block;
text-align: left;
/* for transition effects */
height: 0;
overflow: hidden;
-webkit-transition: height .25s ease .1s;
-moz-transition: height .25s ease .1s;
-o-transition: height .25s ease .1s;
-ms-transition: height .25s ease .1s;
transition: height .25s ease .1s;
}
/*On Hover */
ul#nav li:hover > ul {
opacity: 1; filter: alpha(opacity=100);
}
ul#nav li:hover > ul li {
height: 42px;
overflow: visible;
border-bottom: 1px solid #26272C;
color: #ffffff;
}
ul#nav li:hover > ul li:last-child { border: none; }
/* Sub Menu Anchor links */
ul#nav ul li a {
padding: 6px 15px;
margin: 0;
white-space: nowrap;
font-size: 13px;
}
Any help would be awesome!
add the following at the end of your css script
ul#nav ul li a:hover{
color:red;
}
Example:
#nav-wrap ul, #nav-wrap li, #nav-wrap a {
margin: 0;
padding: 0;
border: none;
outline: none;
}
/* nav-wrap */
#nav-wrap {
position: relative;
font: 15px raleway-heavy, sans-serif;
text-transform: uppercase;
letter-spacing: 1.5px;
float: right;
margin-top: 32px;
margin-right: 20px;
z-index: 99999;
}
/* hide toggle button */
#nav-wrap > a.mobile-btn {
display: none;
border-radius: 3px;
}
ul#nav {
min-height: 48px;
width: auto;
/* left align the menu */
text-align: left;
}
ul#nav li {
position: relative;
list-style: none;
height: 48px;
display: inline-block;
}
/* Links */
ul#nav li a {
/* 8px padding top + 8px padding bottom + 32px line-height = 48px */
display: inline-block;
padding: 8px 11px;
line-height: 32px;
text-decoration: none;
text-align: left;
color: #ffffff;
-webkit-transition: color .2s ease-in-out;
-moz-transition: color .2s ease-in-out;
-o-transition: color .2s ease-in-out;
-ms-transition: color .2s ease-in-out;
transition: color .2s ease-in-out;
}
ul#nav li a:active { background-color: transparent !important; }
ul#nav li:hover > a,
ul#nav li.current a { color: #00b2ee; }
/* adds down arrow */
ul#nav span:after {
width: 0;
height: 0px;
border: 4px solid transparent;
border-bottom: none;
border-top-color: #00b2ee;
content: '';
vertical-align: middle;
display: inline-block;
position: relative;
right: 5px;
}
/* Sub Menu
----------------------------------------------------- */
ul#nav ul {
position: absolute;
top: 100%;
left: 0;
background: #c7c7c7;
min-width: 100%;
border-radius: 5px 5px 7px 7px;
/* for transition effects */
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity .25s ease .1s;
-moz-transition: opacity .25s ease .1s;
-o-transition: opacity .25s ease .1s;
-ms-transition: opacity .25s ease .1s;
transition: opacity .25s ease .1s;
}
/* Third level sub menu
ul#nav ul ul {
position: absolute;
top: 0;
left: 100%;
border-radius: 0 3px 3px 3px;
}
*/
ul#nav ul li {
padding: 0;
display: block;
text-align: left;
/* for transition effects */
height: 0;
overflow: hidden;
-webkit-transition: height .25s ease .1s;
-moz-transition: height .25s ease .1s;
-o-transition: height .25s ease .1s;
-ms-transition: height .25s ease .1s;
transition: height .25s ease .1s;
}
/*On Hover */
ul#nav li:hover > ul {
opacity: 1; filter: alpha(opacity=100);
}
ul#nav li:hover > ul li {
height: 42px;
overflow: visible;
border-bottom: 1px solid #26272C;
color: #ffffff;
}
ul#nav li:hover > ul li:last-child { border: none; }
/* Sub Menu Anchor links */
ul#nav ul li a {
padding: 6px 15px;
margin: 0;
white-space: nowrap;
font-size: 13px;
}
ul#nav ul li a:hover{
color:red;
}
<nav id="nav-wrap">
<a class="mobile-btn" href="#nav-wrap" title="Show navigation">Show navigation</a>
<a class="mobile-btn" href="#" title="Hide navigation">Hide navigation</a>
<ul id="nav" class="nav">
<li>Home</li>
<li class="current">Blog
</li>
<li><span>Resources</span>
<ul>
<li>Alcohol</li>
<li>Drugs</li>
<li>Mental Health</li>
<li>Suicide</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
</ul> <!-- end #nav -->
</nav> <!-- end #nav-wrap -->
I created the fiddle using your code. While hovering over the drop down menu links, the text color changes to the blue as being used on the current menu tab. In case you don't want to use blue on text hover in the drop down menu and want to go with the white text links, just remove "ul#nav li:hover > a," from your code and it'll do the work.
Now your new CSS code should look like :-
#nav-wrap ul, #nav-wrap li, #nav-wrap a {
margin: 0;
padding: 0;
border: none;
outline: none;
}
/* nav-wrap */
#nav-wrap {
position: relative;
font: 15px raleway-heavy, sans-serif;
text-transform: uppercase;
letter-spacing: 1.5px;
float: right;
margin-top: 32px;
margin-right: 20px;
z-index: 99999;
}
/* hide toggle button */
#nav-wrap > a.mobile-btn {
display: none;
border-radius: 3px;
}
ul#nav {
min-height: 48px;
width: auto;
/* left align the menu */
text-align: left;
}
ul#nav li {
position: relative;
list-style: none;
height: 48px;
display: inline-block;
}
/* Links */
ul#nav li a {
/* 8px padding top + 8px padding bottom + 32px line-height = 48px */
display: inline-block;
padding: 8px 11px;
line-height: 32px;
text-decoration: none;
text-align: left;
color: #ffffff;
-webkit-transition: color .2s ease-in-out;
-moz-transition: color .2s ease-in-out;
-o-transition: color .2s ease-in-out;
-ms-transition: color .2s ease-in-out;
transition: color .2s ease-in-out;
}
ul#nav li a:active { background-color: transparent !important; }
ul#nav li.current a { color: #00b2ee; }
/* adds down arrow */
ul#nav span:after {
width: 0;
height: 0px;
border: 4px solid transparent;
border-bottom: none;
border-top-color: #00b2ee;
content: '';
vertical-align: middle;
display: inline-block;
position: relative;
right: 5px;
}
/* Sub Menu
----------------------------------------------------- */
ul#nav ul {
position: absolute;
top: 100%;
left: 0;
background: #c7c7c7;
min-width: 100%;
border-radius: 5px 5px 7px 7px;
/* for transition effects */
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity .25s ease .1s;
-moz-transition: opacity .25s ease .1s;
-o-transition: opacity .25s ease .1s;
-ms-transition: opacity .25s ease .1s;
transition: opacity .25s ease .1s;
}
/* Third level sub menu
ul#nav ul ul {
position: absolute;
top: 0;
left: 100%;
border-radius: 0 3px 3px 3px;
}
*/
ul#nav ul li {
padding: 0;
display: block;
text-align: left;
/* for transition effects */
height: 0;
overflow: hidden;
-webkit-transition: height .25s ease .1s;
-moz-transition: height .25s ease .1s;
-o-transition: height .25s ease .1s;
-ms-transition: height .25s ease .1s;
transition: height .25s ease .1s;
}
/*On Hover */
ul#nav li:hover > ul {
opacity: 1; filter: alpha(opacity=100);
}
ul#nav li:hover > ul li {
height: 42px;
overflow: visible;
border-bottom: 1px solid #26272C;
color: #ffffff;
}
ul#nav li:hover > ul li:last-child { border: none; }
/* Sub Menu Anchor links */
ul#nav ul li a {
padding: 6px 15px;
margin: 0;
white-space: nowrap;
font-size: 13px;
}
In case you want to use some different color while hovering over the drop down text links, you need to use this code separately in the css :-
ul#nav li:hover > a {color:your color name or color code}
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
If you're hover a li, a dropdown menu appears. If you take the pointer down to the ul that appears when you hover, I want the link still have a underline until you take the arrow away from the ul or link. This way you know which menu you hovered when the menu drops down.
Any idea how to do this?
#scroll-nav .links li {
list-style: none;
padding: 0;
margin: 0;
display: inline;
}
#scroll-nav .links li ul {
overflow: hidden;
max-height: 0;
-moz-transition-duration: 0.6s;
-webkit-transition-duration: 0.6s;
-o-transition-duration: 0.6s;
transition-duration: 0.6s;
-moz-transition-timing-function: ease-in-out;
-webkit-transition-timing-function: ease-in-out;
-o-transition-timing-function: ease-in-out;
transition-timing-function: ease-in-out;
position:absolute;
top: 35px;
left: -25px;
padding: 0;
padding-top: 0px;
width: 100%;
background: #FFF;
z-index:-1111111111111111;
letter-spacing: 1px !important;
}
#scroll-nav .links li ul a {
letter-spacing: 1px !important;
}
#scroll-nav .links li:hover ul {
max-height: 1000px;
}
#scroll-nav .links a {
margin-right: 40px;
color: #383838;
letter-spacing: 2px;
}
Unfortunately there is no way to affect a parent element, or element placed before the current one, based on an elements hover state through CSS. You might consider an alternate HTML structure to allow an adjacent sibling selection based on the ul's hover state.
Without being able to see your current HTML structure it will be difficult to help any further. Would you mind posting your example to http://jsfiddle.net or a similar site?
#scroll-nav .links li:hover ul {
max-height: 1000px;
text-decoration: underline;
}
So right now I have a working setup so that when the nav is bigger than the screen then a picture slider down works out. However, the problem is that the nav does not minisize soon enough as it goes over the logo. I want it to be more sensitive to take the logo size into account as well.
Right now this is how I'm achieving this.
HERE IS THE https://jsfiddle.net/q2ozq1q2/3/
/* primary navigation
--------------------------------------------------------------------- */
#nav-wrap ul, #nav-wrap li, #nav-wrap a {
margin: 0;
padding: 0;
border: none;
outline: none;
}
/* nav-wrap */
#nav-wrap {
position: relative;
font: 22px raleway-bold, sans-serif;
float: right;
margin-top: 36px;
margin-right: 20px;
z-index: 99999;
}
/* hide toggle button */
#nav-wrap > a.mobile-btn {
display: none;
border-radius: 3px;
}
ul#nav {
min-height: 48px;
width: auto;
/* left align the menu */
text-align: left;
}
ul#nav li {
position: relative;
list-style: none;
height: 48px;
display: inline-block;
}
/* Links */
ul#nav li a {
/* 8px padding top + 8px padding bottom + 32px line-height = 48px */
display: inline-block;
padding: 8px 11px;
line-height: 32px;
text-decoration: none;
text-align: left;
color: #14C9CF;
-webkit-transition: color .2s ease-in-out;
-moz-transition: color .2s ease-in-out;
-o-transition: color .2s ease-in-out;
-ms-transition: color .2s ease-in-out;
transition: color .2s ease-in-out;
}
ul#nav li a:active { background-color: transparent !important; }
ul#nav li:hover > a,
ul#nav li.current a { color: #fff; }
/* adds down arrow */
ul#nav span:after {
width: 0;
height: 0px;
border: 4px solid transparent;
border-bottom: none;
border-top-color: #8a8383;
content: '';
vertical-align: middle;
display: inline-block;
position: relative;
right: 5px;
}
/* Sub Menu
----------------------------------------------------- */
ul#nav ul {
position: absolute;
top: 100%;
left: 0;
background: #1f2024;
min-width: 100%;
border-radius: 0 0 3px 3px;
/* for transition effects */
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity .25s ease .1s;
-moz-transition: opacity .25s ease .1s;
-o-transition: opacity .25s ease .1s;
-ms-transition: opacity .25s ease .1s;
transition: opacity .25s ease .1s;
}
/* Third level sub menu
ul#nav ul ul {
position: absolute;
top: 0;
left: 100%;
border-radius: 0 3px 3px 3px;
}
*/
ul#nav ul li {
padding: 0;
display: block;
text-align: left;
/* for transition effects */
height: 0;
overflow: hidden;
-webkit-transition: height .25s ease .1s;
-moz-transition: height .25s ease .1s;
-o-transition: height .25s ease .1s;
-ms-transition: height .25s ease .1s;
transition: height .25s ease .1s;
}
/*On Hover */
ul#nav li:hover > ul { opacity: 1; filter: alpha(opacity=100); }
ul#nav li:hover > ul li {
height: 42px;
overflow: visible;
border-bottom: 1px solid #26272C;
}
ul#nav li:hover > ul li:last-child { border: none; }
/* Sub Menu Anchor links */
ul#nav ul li a {
padding: 6px 15px;
margin: 0;
white-space: nowrap;
font-size: 13px;
}
You can see that it achieves it by this:
/* hide toggle button */
#nav-wrap > a.mobile-btn {
display: none;
border-radius: 3px;
}
But it does not use the the logo to know exactly when it starts or stops. So the nav will overlay onto the logo. Is there a way to account for the logo?
EDIT
https://jsfiddle.net/q2ozq1q2/3/
If I understand you correctly, you can change the width on the media-query to around 990px like so: (on line 289 in the fiddle)
#media only screen and (max-width: 990px) {
Hey u can resize both image and navigation bar when viewed on smaller screen :
Use following css as example:
img {
max-width:250px;
max-height:250px;
}
#nav-wrap ul#nav {
position:absolute;
width:100%;
}
ul#nav ul li a{
word-break:break-all;
width:100%;
}
You should add a class for img tag -
header .logo a {
display: block;
margin: 0;
padding: 0;
border: none;
outline: none;
}
header .logo a img{
width: 210px;
height: 34px;
}
JSFIDDLE
When you hover over one of the first links (products,technology, etc), a dropdown menu appears and the link turns orange. It continues to stay orange as you hover over the dropdown menu. I remember doing something for it to behave this way, and I want to get rid of it now, but I cannot for the life of me remember how I did this, and cannot undo it. Anyone see how I can undo this?
Here's the css:
#navbar{
list-style: none;
float: right;
margin-top: 54px;
position: relative;
}
.firstnavmenu{
margin-top: 10px;
}
/*first level*/
#navbar li{
float:left;
width: 140px;
text-align: center;
-webkit-transition: background 0.3s ease;
-moz-transition: background 0.3s ease;
-o-transition: background 0.3s ease;
transition: background 0.3s ease;
}
#navbar li a{
text-decoration: none;
font-family: "Open Sans", sans-serif;
font-size: 11px;
letter-spacing: 1px;
color: #524F4F;
font-weight: 600;
-webkit-transition: color 0.3s ease;
-moz-transition: color 0.3s ease;
-o-transition: color 0.3s ease;
transition: color 0.3s ease;
}
#navbar li:hover > a{
color: #f3a82e;
}
#navbar li:hover > ul{
height: 250px;
}
/* second level */
#navbar li ul{
list-style: none;
position: absolute;
top: 100%;
height:0px;
overflow: hidden;
-o-transition: all .3s ease-in;
-webkit-transition: all .3s ease-in;
-moz-transition: all .3s ease-in;
transition: all .3s ease-in;
}
#navbar li ul li:last-child{
padding-bottom: 10px;
border-bottom-right-radius: 8px;
border-bottom-left-radius: 8px;
-webkit-border-bottom-right-radius: 8px;
-webkit-border-bottom-left-radius: 8px;
-moz-border-bottom-right-radius: 8px;
-moz-border-bottom-left-radius: 8px;
}
#navbar li ul li{
float: none;
position: relative;
width: 140px;
height: auto;
background-color:rgba(255,255,255,0.7);
color:rgba(255,255,255,0.7);
padding-top:5px;
padding-bottom: 5px;
}
#navbar li ul li a{
padding-left: 10px;
text-align: left;
padding-top: 6px;
width: 90%;
height: 100%;
display: block;
}
than use
#navbar li a:hover{
color: #f3a82e;
}
instead of this
#navbar li:hover > a{
color: #f3a82e;
}
http://jsfiddle.net/fp5TM/1/