I have a dropdown menu nested in a parent dropdown. The parent dropdown is set to overflow: hidden, and I use max-height to animate the height transition. So it must have overflow: hidden for that animation to work properly. The problem is now I have a child dropdown nested in that parent dropdown. Becuase the parent dropdown is overflow: hidden, so the child dropdown is hide by the parent dropdown.
My question is: Is there a way to animate the height of the parent dropdown and also show the child dropdown? I do not want to animate the opacity. I think for max-height to animate, we must set the dropdown to overflow: hidden, but this will hide all the child dropdown. Maybe there is another way?
<div class="nav">
<div class="nav-item">
Nav Item
<ul class="dropdown">
<li> LINK</li>
<li>
LINK
<ul class="inner-dropdown">
<li>link</li>
<li>link</li>
</ul>
</li>
<li> LINK</li>
<ul/>
</div>
</div>
body {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
.nav-item{
width:100%
height:20px;
background:#56bcf9;
text-align:center;
font-family: 'Arial';
font-weight: 700;
padding: 30px 0;
cursor: pointer;
}
.nav-item:hover .dropdown{
max-height: 500px;
}
.dropdown{
width:500px;
background:#666;
position:absolute;
max-height: 0;
transition: max-height .5s ease-in;
overflow: hidden;
}
.dropdown li {
padding: 15px;
}
.inner-dropdown {
position: absolute;
background: pink;
width: 200px;
top: 60px;
left: 540px;
}
body {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
.nav-item{
width:100%
height:20px;
background:#56bcf9;
text-align:center;
font-family: 'Arial';
font-weight: 700;
padding: 30px 0;
cursor: pointer;
}
.nav-item:hover .dropdown{
max-height: 500px;
}
.dropdown{
width:500px;
background:#666;
position:absolute;
max-height: 0;
transition: max-height .5s ease-in;
overflow: hidden;
}
.dropdown li {
padding: 15px;
}
.inner-dropdown {
position: absolute;
background: pink;
width: 200px;
top: 60px;
left: 540px;
}
<div class="nav">
<div class="nav-item">
Nav Item
<ul class="dropdown">
<li> LINK</li>
<li>
LINK
<ul class="inner-dropdown">
<li>link</li>
<li>link</li>
</ul>
</li>
<li> LINK</li>
<ul/>
</div>
</div>
By setting overflow: visible; In the dropdown class, the menu is set by giving the animation under the inner-dropdown menu.
body {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
.nav-item{
max-width:500px;
background:#56bcf9;
text-align:center;
font-family: 'Arial';
font-weight: 700;
cursor: pointer;
padding:30px 0;
}
.nav-item:hover .dropdown{
visibility:visible;
max-height: 1000px;
}
.dropdown{
width:500px;
background:#666;
position:absolute;
max-height: 0px;
transition: all .5s ease-in;
overflow: visible;
top:60px;
padding:0;
visibility:hidden;
}
.dropdown li {
padding: 15px 0;
color:white;
}
.dropdown li:hover .inner-dropdown{
max-height:500px;
}
.dropdown li:hover .inner-dropdown li{
opacity: 1;
}
.inner-dropdown {
position: absolute;
background: red;
width: 200px;
top: 80px;
left: 500px;
max-height:0;
padding:0;
transition: all .5s ease-in-out;
}
.inner-dropdown li {
opacity: 0;
transition: all .5s ease-in-out;
}
<div class="nav">
<div class="nav-item">
Nav Item
<ul class="dropdown">
<li> LINK</li>
<li>
LINK
<ul class="inner-dropdown">
<li>link</li>
<li>link</li>
</ul>
</li>
<li> LINK</li>
<ul/>
</div>
</div>
Related
This question already has answers here:
Transitions on the CSS display property
(37 answers)
Closed 3 years ago.
.topmenu-header ul {
position: absolute;
list-style-type: none;
width: 100%;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul li {
cursor: pointer;
float: left;
color: white;
padding: 15px 60px 15px 25px;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul .dropdown {
position: relative;
background: red;
padding: 16px;
color: white;
transition: all 5s ease 0s;
}
.topmenu-header .dropdown {
top: 100%;
left: inherit;
display: none;
}
.topmenu-header li:hover .dropdown {
background: pink;
transition-delay: 0s;
display: block;
}
<header class="topmenu-header">
<ul>
<li class="top-left-list-border">CATEGORIES
<div class="dropdown">
<h3>DONE</h3>
</div>
</li>
<li>SPECIALS
<div class="dropdown">
<h3>DONE2</h3>
</div>
</li>
<li>QUICK LINK</li>
<li>MANUFACTURES</li>
<li>INFO</li>
<li class="top-right-list-border">SHIPPING & RETURNS</li>
</ul>
</header>
I am trying to add transition on my dropdown hover. But i can't recognize the right place, as where i have to write the code. I want if i hover the menu. the drop down will come up smoothly. It's a mega drop down and come up at quickly on hover. I just wanna make it a little bit slow. So it look awesome.
you mainly need to add transition to your submenu class. I have add the code let me know if you have any confusion
.topmenu-header ul {
position: absolute;
list-style-type: none;
width: 100%;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul li {
cursor: pointer;
float: left;
color: white;
padding: 15px 60px 15px 25px;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul .dropdown {
position: relative;
background: red;
padding: 16px;
color: white;
transition: all 5s ease 0s;
}
.sub-menu-parent {
position: relative;
}
.sub-menu {
background: pink;
text-align: center;
display: block;
visibility: hidden;
/* hides sub-menu */
opacity: 0;
position: absolute;
top: 100%;
left: 0;
width: 100%;
z-index: -1;
transition: all 0.3s ease-in-out 0s
}
.sub-menu-parent:focus .sub-menu,
.sub-menu-parent:focus-within .sub-menu,
.sub-menu-parent:hover .sub-menu {
visibility: visible;
/* shows sub-menu */
opacity: 1;
z-index: 1;
transition-delay: 0s, 0s, 0.3s;
}
.topmenu-header .dropdown {
top: 100%;
left: inherit;
display: none;
}
<header class="topmenu-header">
<ul>
<li class="top-left-list-border">CATEGORIES
<div class="dropdown">
<h3>DONE</h3>
</div>
</li>
<li class="sub-menu-parent">SPECIALS
<div class="sub-menu">
<h3>DONE2</h3>
</div>
</li>
<li>QUICK LINK</li>
<li>MANUFACTURES</li>
<li>INFO</li>
<li class="top-right-list-border">SHIPPING & RETURNS</li>
</ul>
</header>
Transition opacity while changing max-height (but not transitioning that). Please note that I also removed float: left; and instead made the ul a flex container.
.topmenu-header ul {
position: relative;
list-style-type: none;
display: flex;
background: rgba(255, 0, 0, 1);
flex-wrap: wrap;
}
.topmenu-header ul li {
cursor: pointer;
color: white;
padding: 15px 60px 15px 25px;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul .dropdown {
position: absolute;
background: red;
color: white;
max-height: 0;
overflow: hidden;
transition: opacity .4s ease 0s;
}
.topmenu-header .dropdown {
left: inherit;
opacity: 0;
}
.topmenu-header li:hover .dropdown {
background: pink;
padding: 16px;
max-height: 1000px;
opacity: 1;
}
<header class="topmenu-header">
<ul>
<li class="top-left-list-border">CATEGORIES
<div class="dropdown">
<h3>DONE</h3>
</div>
</li>
<li>SPECIALS
<div class="dropdown">
<h3>DONE2</h3>
</div>
</li>
<li>QUICK LINK</li>
<li>MANUFACTURES</li>
<li>INFO</li>
<li class="top-right-list-border">SHIPPING & RETURNS</li>
</ul>
</header>
Not all CSS properties can be animated. Here is the MDN list of properties that can be animated - you will see that display is not on the list, so animating the change from display:hidden to display:block cannot be done.
Look through the above list and decide which property you want to animate, and you will be able to create something that works. In the below example, I just picked the height property and you can see that it animates just fine.
.topmenu-header ul {
position: absolute;
list-style-type: none;
width: 100%;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul li {
cursor: pointer;
float: left;
color: white;
padding: 15px 60px 15px 25px;
background: rgba(255, 0, 0, 1);
}
.topmenu-header ul .dropdown {
position: relative;
background: red;
padding: 16px;
color: white;
transition: all 1.5s ease 0s;
}
.topmenu-header .dropdown {
top: 100%;
left: inherit;
Xdisplay: none;
height:0px;
overflow:hidden;
}
.topmenu-header li:hover .dropdown {
background: pink;
transition-delay: 0s;
xdisplay: block;
height:50px;
}
<header class="topmenu-header">
<ul>
<li class="top-left-list-border">CATEGORIES
<div class="dropdown">
<h3>DONE</h3>
</div>
</li>
<li>SPECIALS
<div class="dropdown">
<h3>DONE2</h3>
</div>
</li>
<li>QUICK LINK</li>
<li>MANUFACTURES</li>
<li>INFO</li>
<li class="top-right-list-border">SHIPPING & RETURNS</li>
</ul>
</header>
i'm writing on my website and i've some problems with the following code (full code on codepen):
<section class="sidebar">
<ul class="sidebar-menu clearfix">
<li class="sidebar-menu-item">HOME</li>
<li class="sidebar-menu-item">PORTFOLIO</li>
<li class="sidebar-menu-item">BLOG</li>
<li class="sidebar-menu-item">ABOUT ME</li>
<li class="sidebar-menu-item">CONTACT</li>
</ul>
</section>
https://codepen.io/anon/pen/pdErVq
As you can see all the :after elements are aligned in the first row.
How can i expand the elements in the proper <li> tags?
Give position:relative to .sidebar-menu > li class.
.sidebar {
position: fixed;
background-color: #333;
opacity: 0.75;
width: 300px;
height: 100%;
left: -0px;
top: 0;
}
.sidebar-menu {
position: relative;
top: 100px;
padding-left: 20px;
}
.sidebar-menu > li {
color: #fff;
margin-right: 10px;
list-style: none;
font-size: 25px;
font-style: italic;
padding: 10px 5px;
cursor: pointer;
-webkit-transition: all 0.5s;
transition: all 0.5s;
position:relative;
}
.sidebar > ul > li:after {
content: "";
display: block;
position: absolute;
top: 10px;
right: 0;
background-color: rgba(250,250,250,0.5);
width: 0;
height: 37px;
-webkit-transition: all 0.5s;
transition: all 0.5s;
}
.sidebar-menu > li:hover:after {
width: 280px;
}
<section class="sidebar">
<ul class="sidebar-menu clearfix">
<li class="sidebar-menu-item">HOME</li>
<li class="sidebar-menu-item">PORTFOLIO</li>
<li class="sidebar-menu-item">BLOG</li>
<li class="sidebar-menu-item">ABOUT ME</li>
<li class="sidebar-menu-item">CONTACT</li>
</ul>
</section>
Your li's need position: relative.
You can try this Demo
li{position:relative}
li a{position:absolute;}
I am added a tag in li
I have a task to create a drop-down menu and i create it with using absolute and negative value but i can change my mind i want to create a drop-down without using absolute there is any possibility to create and how can do it kindly help in this query
.mainmenu {
position: relative;
cursor: pointer;
display: inline-block;
padding: 15px;
-webkit-transition: all .5s;
}
.submenu {
position: absolute;
height: 0px;
opacity: 0;
-webkit-transition: all .5s;
}
.mainmenu:hover {
border: 1px solid #000;
-webkit-transition: all .5s;
}
.mainmenu:hover .submenu {
border: 1px solid #000;
padding: 50px;
height: auto;
top: 100%;
left: -1px;
opacity: 1;
-webkit-transition: all .5s;
}
.mainmenu:hover .hide_line {
height: 5px;
width: 100%;
position: absolute;
top: 100%;
right: 0px;
background: #fff;
z-index: 1000;
}
<div class="mainmenu">
Menu
<div class="hide_line">
</div>
<div class="submenu">
submenu
</div>
</div>
You can use list for this purpose
.mainmenu a{
text-decoration:none;
color:#000000;
}
.mainmenu {
position: relative;
cursor: pointer;
display: inline-block;
padding: 15px;
-webkit-transition: all .5s;
list-style:none;
}
.mainmenu > li{
padding-left:0px;
margin-left:0px;
}
.submenu {
opacity:0;
list-style:none;
}
.mainmenu:hover .submenu {
border: 1px solid #000;
height: auto;
opacity: 1;
-webkit-transition: all .5s;
}
.submenu li{
padding-left:0px;
margin-left:0px;
}
<ul class="mainmenu">
<li><a href='#'>Main Menu</a>
<ul class="submenu">
<li><a href='#'>Sub menu</a></li>
</ul>
</li>
</ul>
I hope you can do rest of the formatting
I'm having an issue on my menu items.
I have my menu items styled so whenever I hover over a list item, it dims the hovered item.
However, whenever I hover on one list item, it seems to be affecting and dimming all list items.
I narrowed down the problem. It works perfectly fine when my menu-bar-container div is positioned relative. However, I want this menu-bar-container div to be fixed.
Anyone know what seems to be the issue? Appreciate the help in advance.
Here is the HTML:
<div id="menu-bar-container">
<h1> GENE WONG OFFICIAL PAGE </h1>
<div class="clear"> </div>
<div id="menu-bar-2">
<ul>
<li class="fade">HOME</li>
<li class="fade">NEWS</li>
<li class="fade">BIOGRAPHY</li>
<li class="fade">MEDIA</li>
<li class="fade">PROJECTS</li>
<li class="fade active">GEAR</li>
<li class="fade">CONTACT</li>
</ul>
</div>
</div>
and here's the CSS:
#menu-bar-container {
background: url(images/hp/header-bg.png);
min-width: 100%;
height: 110px;
margin: 0 auto;
text-align: center;
border-bottom: 1px solid #2F2F2F;
position: fixed;
z-index: 10;
}
#menu-bar-2 {
display: inline-block;
margin: 0 auto;
height: 32px;
max-width: 100%;
}
#menu-bar-2 ul {
list-style-type: none;
overflow: auto;
margin: 0;
padding: 0;
padding-top: 4px;
height: 30px;
}
#menu-bar-2 li {
float:left;
}
#menu-bar-2 li a {
display: block;
text-decoration: none;
padding: 0px 10px;
font-size: 15px;
top: 10px;
color: white;
}
#menu-bar-2 li.active a {
color:#E20000;
}
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade:hover {
opacity: .7;
}
So i ve been working on this for several hours.. i have a problem in the nav bar where the content refuses to go display: inline. Previous versions worked fine but were too disorganized , code wise. here is my code.
CSS:
body {
background-color: #5C7584;
margin: 0 auto;
//width: 1000px;
width: 100%;
margin-top: 10px;
}
#canvas {
width: 1000px;
margin: 0 auto;
background-color: white;
}
a {
color: #4086b6;
text-decoration: none;
}
///////////////////////////////////
ul, li {
list-style: none;
}
ul li {
//padding-right: 10px;
//padding-left: 10px;
//display: inline;
}
.parentClass {
display: inline;
//position: relative;
list-style: none;
//float: left;
}
.dropDown {
position: relative;
background-color: lightcyan;
display: block;
list-style: inherit;
//text-align: right;
//background-color: lightcyan;
width: auto;
height: 0px;
visibility: hidden;
opacity: 0;
-webkit-transition: all .25s;
-moz-transition: all .25s;
-ms-transition: all .25s;
-o-transition: all .25s;
transition: all .5s;
}
#linkline{
}
.parentClass:hover {
background-color: lightcyan;
}
.parentClass:hover .dropdown {
opacity: 1;
visibility: visible;
height: auto;
}
/////////////////////////////
#toplinks a {
//padding-left: 0px;
text-shadow: 1px 1px lightgrey;
}
#toplinks a:hover {
color: lightskyblue;
//border-radius: 50px 50px;
}
#toplinks a:active {
color: white;
}
#top {
height: 102px;
background-image: url("../assets/topbar_plain.png");
background-color: white;
opacity: .9;
z-index: 2;
position: relative;
}
#toplinks {
float: right;
width: 500px;
text-align: right;
padding-right: 30px;
padding-top: 70px;
}
#logo {
background-image: url("../assets/logo_plain.png");
width: 102px;
height: 33px;
float: left;
background-repeat: no-repeat;
margin-top: 40px;
margin-left: 80px;
}
HTML:
<div id="top" >
<div id="canvas">
<div id="toplinks">
<ul class="linkline">
<li id="indexx" class="parentClass">Overview
<ul></ul>
</li>
<li class="parentClass">Services
<ul class="dropDown">
<li class="c2"> DDoS Mitigation </li>
<li class="c1"> Server Hosting </li>
</ul>
</li>
<li class="parentClass">AboutUs
<ul class="dropDown">
<li class="c2"> Link 1 </li>
<li class="c1"> Link 2 </li>
<li class="c2"> Link 3 </li>
</ul>
</li>
</ul>
</div>
</div>
</div>
Try with:
display:inline-block
ul {
list-style: none;
}
li {
float: left;
display: block;
margin: 0 1em 0 0;
border: 1px solid purple;
}
<ul>
<li>Menu item 1</li>
<li>Menu item 2</li>
</ul>
Hi, I simplified your code down to the lists and their styling which is what you need to fix. Make sure ul is list-style none and the li's in that list are float left display block and then style from there.
It looks like something strange is happening because of the <ul class="dropDown"> nested inside the <li class="parentClass">. Try this as a start:
.dropDown {
display: none;
}
.parentClass {
display: inline-block;
}
Try to change the parentClass like that.
.parentClass {
display: inline-block;
position: relative;
list-style: none;
float: left;
}