CSS drop-down menu: z-index issue - css

I've got two problems with my CSS drop-down menu: JSFiddle
1) Transitions: Would like the menu to slide-down when the mouse switches to it to open it. The previously opened menu should slide-up to close.
#nav ul li ul
{
-webkit-transition:height .5s ease-in;
-moz-transition:height .5s ease-in;
-o-transition:height .5s ease-in;
-ms-transition:height .5s ease-in;
transition:height .5s ease-in;
}
This doesn't seem to work; possibly under the wrong "ul li" selector, though I tried others.
2) Bring the parent item ("Menu1", "Menu2") on top of the menu item list so that it covers the top border of the first child. That is, there should be no border between "Menu1" and "Item1" since "Menu1" doesn't have a bottom border, but looks like it does since "Item1" is on top of it.
Tried playing with z-index, but can't get it working. Neither the transitions.
I realize the menu is a bit convoluted and probably has more CSS than necessary.

What about it? JSFiddle
#nav ul {
padding: 0;
margin: 0;
list-style: none;
}
#nav ul li {
display: inline-block;
border: 1px solid #FFF;
border-bottom: 0;
border-radius: 5px;
margin: 0 15px;
position: relative;
-webkit-transition: border-color 0.2s ease-in;
-moz-transition: border-color 0.2s ease-in;
-o-transition: border-color 0.2s ease-in;
-ms-transition: border-color 0.2s ease-in;
transition: border-color 0.2s ease-in;
}
#nav ul li a {
color: #8799B3;
display: block;
padding: 10px 6px;
border: 0;
-webkit-transition: color 0.2s ease-in;
-moz-transition: color 0.2s ease-in;
-o-transition: color 0.2s ease-in;
-ms-transition: color 0.2s ease-in;
transition: color 0.2s ease-in;
}
#nav ul li:hover {
color: #415161;
border-color: #E9E9E9;
}
#nav ul li a:hover {
color: #415161;
}
#nav ul li ul {
opacity: 0;
visibility: hidden;
text-decoration: none;
line-height: 1;
color: #8799B3;
background: #FFF;
position: absolute;
top: calc(100% - 5px);
left: -1px;
z-index: 1000;
width: 165px;
border: 0;
}
#nav ul li:hover ul {
opacity: 1;
visibility: visible;
}
#nav ul li ul li {
border: 0;
display: block;
font-size: 14px;
margin: 0;
-webkit-transition: background 0.2s ease-in;
-moz-transition: background 0.2s ease-in;
-o-transition: background 0.2s ease-in;
-ms-transition: background 0.2s ease-in;
transition: background 0.2s ease-in;
}
#nav ul li ul li:hover {
border: none;
color: #415161;
background: #F7F9FB;
}
#nav ul li ul li a {
padding: 10px;
border: none;
color: #8799B3;
border-left: 1px solid #E9E9E9;
border-right: 1px solid #E9E9E9;
border-bottom: 1px solid #E9E9E9;
}
#nav ul li ul li:first-child a {
border-top: 1px solid #E9E9E9;
border-radius: 0 5px 0 0;
}
#nav ul li ul li:last-child a {
border-bottom: 1px solid #E9E9E9;
border-radius: 0 0 5px 5px;
}
#nav ul li ul {
-webkit-transition: opacity 0.2s ease-in;
-moz-transition: opacity 0.2s ease-in;
-o-transition: opacity 0.2s ease-in;
-ms-transition: opacity 0.2s ease-in;
transition: opacity 0.2s ease-in;
}
<div id="nav">
<ul>
<li>
Menu1
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</li>
<li>
Menu2
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</li>
<li>
Menu3
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</li>
</ul>
</div>

Related

Negative text indent, translate on hover bug (firefox)

I'm experiencing a firefox specific bug with a simple menu I've built
It's a ul-list that has an on-hover effect for the list items, the list items have transform:translateX(12px) applied on hover, and the text links have a negative indent applied at all times, the combination of the two create a Firefox specific bug where part of the text disappears on hover during its animation, looks like its basically being hidden by its own padding because of the negative value.
Here is a JS Fiddle as well as the code, am I missing -moz- css?
https://jsfiddle.net/CultureInspired/9435v0vy/1/
<ul class="menu_desktop">
<li>Home</li>
<li>About</li>
<li>Press</li>
<li>Contact</li>
</ul>
CSS:
.menu_desktop {
list-style-type: none;
margin: 80px;
padding: 0;
}
.menu_desktop li {
background: #fff;
margin-bottom: 10px;
text-indent: -.8em;
text-transform: uppercase;
letter-spacing: 6px;
display: table;
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
-ms-transition: all 0.2s ease-out;
-o-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
}
.menu_desktop li:hover {
transform: translateX(12px);
}
.menu_desktop a {
color: #000;
height: 100%;
padding: 8px;
display: block;
text-decoration:none;
}
I've got the same issue with firefox 49.0.2, it seems like a bug.
You can solve this by using margin-left: 12px; instead of the transform you are currently using.
Here is the fix (works in firefox, chrome & ie):
body {
background: lightgray;
}
.menu_desktop {
list-style-type: none;
margin: 80px;
padding: 0;
}
.menu_desktop li {
background: #fff;
margin-bottom: 10px;
text-indent: -.8em;
text-transform: uppercase;
letter-spacing: 6px;
display: table;
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
-ms-transition: all 0.2s ease-out;
-o-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
}
.menu_desktop li:hover {
margin-left: 12px;
}
.menu_desktop a {
color: #000;
height: 100%;
padding: 8px;
display: block;
text-decoration:none;
}
<ul class="menu_desktop">
<li>Home</li>
<li>About</li>
<li>Press</li>
<li>Contact</li>
</ul>

How to make CSS3 transition working for border-bottom property which starts from bottom to top

I have 2 examples below which display 4 links and hovering upon them display border bottom with ease effect.
In the Example 1 the border-bottom display from top-bottom. I have tried revering with the padding property which is there in Example 2, Its not consistent across the browsers and it does not works properly.
Example 1: transition default functionality (transition from top-bottom)
<!DOCTYPE html><html class=''>
<head>
<style class="cp-pen-styles">
body {
padding: 50px;
}
a, a:hover {
text-decoration: none;
}
li {
position: relative;
padding-bottom: 3px;
margin-right: 10px;
display: inline;
}
li a {
border-bottom: 0em solid transperant;
color: #777;
}
li:focus > a,
li:hover > a,
li:active > a {
border-bottom: 0.313em solid #206E9F;
transition: border-bottom .2s ease-in-out;
-webkit-transition: border-bottom .2s ease-in-out;
-moz-transition: border-bottom .2s ease-in-out;
-ms-transition: border-bottom .2s ease-in-out;
}
|
</style>
</head>
<body>
<ul>
<li>HOME</li>
<li>PAGE</li>
<li>ABOUT US</li>
<li>CONTACT US</li>
</ul>
</body>
</html>
Example 2: transition from bottom-top (using padding - Compatibility issue with IE browser)
<!DOCTYPE html><html class=''>
<head>
<style class="cp-pen-styles">
body {
padding: 50px;
}
a, a:hover {
text-decoration: none;
}
li {
position: relative;
padding-bottom: 3px;
margin-right: 10px;
display: inline;
}
li a {
color: #777;
padding-bottom:0.4em;
border-bottom: 0em solid transperant;
}
li:focus > a,
li:hover > a,
li:active > a {
padding-bottom:0em;
border-bottom: 0.313em solid #206E9F;
transition: all .2s ease-in;
-webkit-transition: all .2s ease-in;
-moz-transition: all .2s ease-in;
-ms-transition: all .2s ease-in;
}
</style></head><body>
<ul>
<li>HOME</li>
<li>PAGE</li>
<li>ABOUT US</li>
<li>CONTACT US</li>
</ul>
</body></html>
How to make CSS3 transition working for border-bottom property which starts from bottom to top.
You can simulate your desired outcome by using :after or :before pseudo elements. This way you'll have much greater control over the desired effect (like adding various transforms).
body {
padding: 50px;
}
a {
text-decoration: none;
}
li {
display: inline;
margin-right: 10px;
}
li a {
border-bottom: 0 solid transparent;
color: #777;
display: inline-block;
padding-bottom: 3px;
position: relative;
}
li a > .fancy-line {
background-color: transparent;
content: "";
display: block;
height: 0;
position: absolute;
bottom: 0;
left: 0;
right: 0;
-o-transition: background-color 0.2s ease-in-out, height 0.2s ease-in-out;
-ms-transition: background-color 0.2s ease-in-out, height 0.2s ease-in-out;
-moz-transition: background-color 0.2s ease-in-out, height 0.2s ease-in-out;
-webkit-transition: background-color 0.2s ease-in-out, height 0.2s ease-in-out;
transition: background-color 0.2s ease-in-out, height 0.2s ease-in-out;
}
li a:hover > .fancy-line {
background-color: #206E9F;
height: 3px;
}
<ul>
<li>HOME <span class="fancy-line"></span></li>
<li>PAGE <span class="fancy-line"></span></li>
<li>ABOUT US <span class="fancy-line"></span></li>
<li>CONTACT US <span class="fancy-line"></span></li>
</ul>
You can do this with a pseudo-element and a transform rather than a border.
body {
padding: 50px;
}
a,
a:hover {
text-decoration: none;
}
li {
position: relative;
padding-bottom: 3px;
margin-right: 10px;
display: inline;
}
li a {
border-bottom: 0em solid transperant;
color: #777;
position: relative;
}
li > a::after,
li > a::after,
li > a::after {
content: '';
position: absolute;
width: 100%;
height: .313em;
background: #206E9F;
top: 100%;
left: 0;
transform-origin: center bottom;
transform: scaleY(0);
transition: transform .2s ease-in-out;
}
li:focus > a::after,
li:hover > a::after,
li:active > a::after {
transform: scaleY(1);
}
<ul>
<li>HOME
</li>
<li>PAGE
</li>
<li>ABOUT US
</li>
<li>CONTACT US
</li>
</ul>

CSS3 transition navigation like Google Chrome Website

Is there a way to get a hover effect like the effect on the Google Chrome website (http://www.google.de/intl/de/chrome/browser/) with CSS3 transition? My problem is, that the animation goes into the wrong direction:
HTML:
<ul>
<li>Nav#1</li>
<li>Nav#2</li>
<li>Nav#3</li>
</ul>
CSS:
ul{ list-style: none; }
ul li{
float: left;
padding: 25px;
-webkit-transition: all 0.4s ease;
-moz-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
}
ul li:hover{ border-bottom: 5px red solid; }
http://jsfiddle.net/HMZKP/
If you apply a padding to the bottom in it's normal state, then remove that padding when hovered you get the desired effect.
ul li {
float: left;
padding: 25px;
-webkit-transition: all 0.4s ease;
-moz-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
border-bottom: 0;
padding-bottom: 5px;
}
ul li:hover {
border-bottom: 5px red solid;
padding-bottom: 0;
}
See this jsfiddle: http://jsfiddle.net/xTjXK/ (Tested in Chrome, Firefox & Safari)

CSS Transition - Issue with Height in UL/LI tags

I am trying to get my CSS transitions down smoothly, but I'm having one last issue. It's pretty superficial I'll admit, but I'd like to get it "fixed" if at all possible. I've tried it in Chrome, Firefox, and IE and it does this in all browsers.
The UL and LI elements that I'm manipulating are part of a navigation toolbar. The toolbar can be seen in the top left corner of the following URL:
http://fretfast.com/templates/clean/sample.php
When you hover over one of the elements that has an expandable list, such as learn, teach, or community, you will see that it expands very smoothly (assuming your browser supports CSS3 transitions, of course); however, when you move your mouse away from the expandable list, the marginal area at the top of the list gets eradicated immediately which makes all the subsequent text shift up too quickly.
For instance, if you hover over learn, an expandable menu will be presented that gives the options of lessons, questions, and tips. However, when you move your mouse out and the menu collapses, the first option (lessons) is instantly pushed up so that it is right below the button's main text (learn).
Here is the CSS that I am using for the navigation bar, but for the life of me I cannot figure out why the height transition only works in one direction.
#topNav {
list-style-type: none; height: 25px; padding: 0; margin: 0;
}
#topNav * { font-size: 15px; }
#topNav li {
float: left; position: relative; z-index: 1;
padding: 0; line-height: 23px; background: none; repeat-x 0 0;
padding-top: 2px;
}
#topNav li:hover {
background-color: #C0C0C0; z-index: 2;
padding-top: 0;
border-top: 2px solid #59B4FF;
}
#topNav li a {
display: block; padding: 0 15px; color: #000; text-decoration: none;
}
#topNav li a:hover { color: #222222; }
#topNav li ul {
opacity: 0; position: absolute; left: 0; width: 8em; background: #C0C0C0;
list-style-type: none; padding: 0; margin: 0;
}
#topNav li:hover ul { opacity: 1; }
#topNav li ul li {
float: none; position: static; height: 0; line-height: 0; background: none;
}
#topNav li:hover ul li {
height: 25px; line-height: 25px;
}
#topNav li ul li a { background: #C0C0C0; }
#topNav li ul li a:hover {
text-indent: 0.3em;
background-color: #59B4FF;
}
#topNav li {
transition: background-color 0.2s ease;
-o-transition: background-color 0.2s ease;
-moz-transition: background-color 0.2s ease;
-webkit-transition: background-color 0.2s ease;
}
#topNav li a {
transition: all 0.2s ease;
-o-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
-webkit-transition: all 0.2s ease;
}
#topNav li ul {
transition: all 0.3s ease;
-o-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-webkit-transition: all 0.3s ease;
}
#topNav li ul li {
transition: height 0.5s ease;
-o-transition: height 0.5s ease;
-moz-transition: height 0.5s ease;
-webkit-transition: height 0.5s ease;
}
#topNav li ul li a {
transition: all 0.3s ease;
-o-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-webkit-transition: all 0.3s ease;
transition: text-indent 0.1s linear;
-o-transition: text-indent 0.1s linear;
-moz-transition: text-indent 0.1s linear;
-webkit-transition: text-indent 0.1s linear;
}
I don't believe it has anything to do with the padding-top specification in #topNav li either, because I just added that today for the border highlighting effect and this problem has been going on for longer than that. Any help is greatly appreciated.
The property that is causing that is a line-height; more specifically this one.
#topNav li:hover ul li {
height: 25px;
line-height: 25px;
}
if you look at the transitions, it's specified only on height. You can change the transition to all, it seems to display ok. If not, probably the best would be to set the line-height at 25px in the non-hovered properties instead of on the hovered (that is, making it fixed)
#topNav li ul li {
transition: all 0.5s ease;
}
How can you debug easily issues related to hover ??
In the Chrome inspector, select the item where the hover is defined, go to the styles tab, choose toggle element state and check hover. Now the state is set to hover permanently. Just go around checking and un-checking pro`perties to see where do you have the problem.

Pure CSS Drop-down Menu Not Displaying Properly in IE8

My pure css drop-down menu works in all major browsers except IE8. There are two issues.
1) The background color of menu doesn't display until the mouse rolls over one of the menu items. (see photo in link below)
http://www.searchtransparency.net/stackoverflow/2.jpg
2) If the menu is exited from the parent link (treatments) it leaves a shortened version of the background displaying. (see photo in link below)
http://www.searchtransparency.net/stackoverflow/1.PNG
CSS:
.menu,
.menu ul,
.menu li,
.menu a {
margin: 0;
padding: 0;
border: none;
outline: none;
z-index:3;
}
.menu {
height: 53px;
width: 994px;
}
.menu li {
position: relative;
list-style: none;
float: left;
display: block;
height: 38px;
padding-top: 15px;
}
.menu li a {
display: block;
padding-left: 44px;
padding-right: 44px;
-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;
margin-top: 0px;
margin-right: 0;
margin-bottom: 0px;
margin-left: 0;
padding-top: 0;
padding-bottom: 0;
}
.menu li:first-child a { border-left: none; }
.menu li:last-child a{ border-right: none; }
.menu li:hover > a { color:#CCC; }
.menu ul {
position: absolute;
top: 53px;
left: 0;
opacity: 0;
-webkit-border-radius: 0 0 5px 5px;
-moz-border-radius: 0 0 5px 5px;
border-radius: 0 0 5px 5px;
-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;
-webkit-box-shadow: 0px 0px 5px 0px #333;
box-shadow: 0px 0px 5px 0px #333;
background-color: #222;
padding-bottom: 15px;
visibility: hidden;
behavior: url(PIE.htc);
}
.menu li:hover > ul {
opacity: 1;
visibility: visible;
}
.menu ul li {
height: 0;
overflow: hidden;
padding: 0;
-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;
}
.menu li:hover > ul li {
height: 25px;
overflow: visible;
}
.menu ul li a {
width: 175px;
margin: 0;
font-size: 12px;
text-shadow: none;
border: none;
padding-left: 25px;
height: 20px;
padding-top: 5px;
}
.menu ul li:last-child a { border: none; }
.menu li li:hover > a {
background-color: #666;
}
HTML:
<ul class="menu">
<li><img src="images/icon-home.png" alt="Home" width="18" height="18" border="0"></li>
<li>Meet The Doctor</li>
<li class="icon-dropdown-arrow">Treatments
<ul>
<li style="font-size:14px; padding-left:15px; padding-top:10px; margin-top:10px;">Skin Resurfacing</li>
<li>Fraxel® Restore</li>
<li style="font-size:14px; padding-left:15px; padding-top:10px; margin-top:0px;">Skin Tightening</li>
<li>Thermage®</li>
<li>Refirme® Photo-Rejuvenation</li>
<li style="font-size:14px; padding-left:15px; padding-top:10px; margin-top:0px;">Cellulite Treatments</li>
<li>LPG Lipomassage™</li>
<li>VelaShape™</li>
<li>Thermage®</li>
<li>Ionithermie Treatment</li>
<li style="font-size:14px; padding-left:15px; padding-top:10px; margin-top:0px;">Injectibles</li>
<li>Dermal Fillers</li>
<li>Botox® Cosmetic</li>
<li style="font-size:14px; padding-left:15px; padding-top:10px; margin-top:0px;">Other</li>
<li>Laser Hair Removal</li>
<li>Skin Treatments (Face & Body)</li>
<li>Skin Rejuvenation</li>
<li>Plastic Surgery</li>
<li>Massage</li>
</ul>
</li>
<li>Specials</li>
<li>Reviews</li>
<li>Contact</li>
</ul>
Code on JsFiddle.net
As i remember IE understand :hover only just for "a" tag.
:last-child doesn't support too, question about :last-child

Resources