menu in css - dropdown menu - css
I have a little problem with my menu. I intend to do a pulldown menu. As I have the code now, the < li > is displayed , but the idea is by click or by hover "Cambio de centro " unfold the < li > that is inside ... Any idea ?
This is my code:
<div class="verticalaccordionIndex">
<img src="Images/botones/ficheros-btn.png" class="verticalaccordion">
<ul>
<li>
<h3>FICHEROS</h3>
<div class="subverticalaccordionIndex">
<ul>
<li>
<h3><a href="SelectCentro.aspx">Cambio de centro <span>+</span></h3>
<ul class="content-menu">
<li class="content-li">Festivos</li>
<li class="content-li">Áreas de trabajo</li>
<li class="content-li">Centros</li>
<li class="content-li">Actividades</li>
<li class="content-li">Espacio de trabajo</li>
<li class="content-li">Cierre de espacios</li>
<li class="content-li">Trabajadores</li>
<li class="content-li">Convenio</li>
</ul>
</li>
<li>
<h3> Gestión de usuarios</h3></li>
</li>
<li>
<li><h3>Salir</h3></li>
</li>
</ul>
</div>
</li>
</ul>
</div>
--------------------CSS
.verticalaccordionIndex>ul {
padding: 0;
list-style: none;
width: 140px;
float: left;
position: relative;
top: -55px;
border-left: 1px solid;
left: 20px;
}
.verticalaccordionIndex>ul>li {
display: block;
height:30px;
list-style: none;
margin: 0;
overflow: hidden;
padding: 0;
text-align:center;
width: 140px;
background-color:TRANSPARENT;
transition: height 0.3s ease-in-out;
-moz-transition: height 0.3s ease-in-out;
-webkit-transition: height 0.3s ease-in-out;
-o-transition: height 0.3s ease-in-out;
float: left;
position: absolute;
z-index: 200;
height:40px;
}
.verticalaccordionIndex img{
float: left;
width: 3%;
height: auto;
display: block;
position: absolute;
top: 206px;
left: 63px;
z-index: 30;
}
.verticalaccordionIndex .archiv {
float: right;
width: 3%;
height: auto;
display: block;
position: absolute;
top: 206px;
left: 203px;
z-index: 60;
cursor: pointer;
}
.verticalaccordionIndex>ul>li>h3 {
display: block;
margin-top: 2em;
padding: 0;
top: -27px;
position: relative;
color: #000;
cursor: pointer;
font-family: 'Forum', sans-serif;
font-size:18px;
text-decoration:none;
background: TRANSPARENT;
width: 140px;
text-align: center;
}
.verticalaccordionIndex>ul>li>div {
margin: 0;
width: 220px;
position: relative;
left: -10px;
top: -40px;
}
.verticalaccordionIndex>ul>li:hover, .verticalaccordionIndex>ul>li:focus {
height: auto;
width: 200px;
}
.verticalaccordionIndex:hover>ul>li:hover>h3 {
color: #000;
background: #000;
height: 0;
top: -28px;
}
.verticalaccordionIndex>ul>li>h3:hover {
cursor:pointer;
}
.subverticalaccordionIndex>ul>li { /* definimos cada item de la lista */
height:40px; /* la altura de las pestañas */
list-style: none;
margin: 0;
overflow: hidden;
padding: 0;
text-align:left;
width: 220px;
background-color: #9a8d84;
transition: height 0.3s ease-in-out;
-moz-transition: height 0.3s ease-in-out;
-webkit-transition: height 0.3s ease-in-out;
-o-transition: height 0.3s ease-in-out;
position: relative;
left: -31px;
color: white;
height: auto;
}
.subverticalaccordionIndex>ul>li>div { /* el contenido oculto */
margin: 0;
overflow: auto;
padding: 10px;
float: left;
}
.subverticalaccordionIndex>ul{
position: relative;
top: 19px;
}
.subverticalaccordionIndex>ul>li:hover { /* que se despliega al poner el cursor del ratón encima */
height: auto;
display: block;
position: relative;
}
.content-li{
list-style: none;
color: white;
border-bottom: 1px solid white;
width: 100%;
position: relative;
left: -30px;
cursor: pointer;
font-family: 'Forum', sans-serif;
font-size: 1em;
}
.content-li a{
color: white;
text-decoration: none;
}
.content-li:hover, .content-li:focus{
background-color: #DCCCC1;
color: #e86308;
}
.subverticalaccordionIndex>ul>li>h3{
margin-bottom: 0.3em;
margin-left: .5em;
}
.subverticalaccordionIndex>ul>li>h3>a{
width: auto;
cursor: pointer;
font-size: 1.1em;
font-family: 'Forum', sans-serif;
width: 140px;
background-color: #9a8d84;
color:#DCCCC1;
width: auto;
}
.subverticalaccordionIndex>ul>li>h3>a:hover{
display: block;
color: #655448
}
.subverticalaccordionIndex>ul>li>a>h3 span{
float: left;
margin-right: 0;
}
.subverticalaccordionIndex>ul>li>h3:hover{
color:#fff;
background-color: #9a8d84;
}
.subverticalaccordionIndex>ul>li>h3>ul {
width: 75%;
}
subverticalaccordionIndex>ul>li>h3>ul.content-menu{
width: 90%;
}
subverticalaccordionIndex>ul>li>h3:hover{
display: block;
height: auto;
}
here is a demo illustrating menu dropdown on parent element hover. Please note this is not possible for onclick using pure css and without javascript.
css
.subverticalaccordionIndex .content-menu { display: none; }
.subverticalaccordionIndex li:hover .content-menu { background:red; display: block; }
<div class="verticalaccordionIndex">
<img src="Images/botones/ficheros-btn.png" class="verticalaccordion">
<ul>
<li>
<h3>FICHEROS</h3>
<div class="subverticalaccordionIndex">
<ul>
<li>
<h3>Cambio de centro <span>+</span></h3>
<ul class="content-menu">
<li class="content-li">Festivos</li>
<li class="content-li">Áreas de trabajo</li>
<li class="content-li">Centros</li>
<li class="content-li">Actividades</li>
<li class="content-li">Espacio de trabajo</li>
<li class="content-li">Cierre de espacios</li>
<li class="content-li">Trabajadores</li>
<li class="content-li">Convenio</li>
</ul>
</li>
<li>
<h3> Gestión de usuarios</h3>
</li>
<li>
<h3>Salir</h3>
</li>
</ul>
</div>
</li>
</ul>
</div>
I tried your code but it is wrong.
You have to know that each <ul> can only contains <li>. But each <li> can contains <ul>
Example :
<ul>
<li>
Company
<ul>
<li>Our team</li>
<li>About</li>
</ul>
</li>
</ul>
You forgot to close some markers or you have opened too many.
I think your problem is here.
Because of that I don't know what you want to do. Like "Sai Deepak" said on your post, provide us any fiddle, because it is hard to understand.
But first, try to correct your code.
Related
CSS Animation for a Vertical Line Going Upwards
i am trying to create a CSS Animation for a vertical line going upwards - the line should be within a specific div I have used gsap - i have used as well ypercent field, however the line starts from below the FirstScene div while i need it to be contained within the FirstScene div gsap.fromTo(".vertical-line",{ yPercent:10 }, {yPercent:0,duration: 5}); * { margin: 0; padding: 0 } .topnav { position: sticky; top: 0; font-size: x-large; background-color: black; position: -webkit-sticky; overflow: hidden; z-index: 1; } ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: black; } li { float: right; padding: 8px; color: white; display: inline; } linkStyle { display: block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; } li i { color: white; text-decoration: none; } li a { color: white; text-decoration: none; } #li-left { float: left; } body { margin: 0px; height: 100%; } .FirstScene { background-color: black; position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; } .line { left: 50%; top: 50%; width=10px; height: 50%; position: absolute; } .vertical-line { border-left: 6px solid blue; height: 100%; } <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.3/gsap.min.js"></script> <div class="topnav"> <ul> <li id="li-left"> <Link to="/" class="linkStyle"> MINA IBRAHIM </Link> </li> <li> <a href="https://github.com/ibrahimmina"> <i class="fa-brands fa-github"></i> </a> </li> <li> <a href="https://www.linkedin.com/in/minasamyibrahim/"> <i class="fa-brands fa-linkedin"></i> </a> </li> <li> .email() </li> <li> <Link to="/about" class="linkStyle"> .about() </Link> </li> </ul> </div> <body> <section class="FirstScene"> <div class="line"> <div class="vertical-line"> </div> </div> </section> </body>
Please use the bellow css for the Vertical Line Going Upwards animations .FirstScene{ background-color: black; position:absolute; top:0px; right:0px; bottom:0px; left:0px; } .vertical-line{ border-left: 6px solid blue; animation-name: line; animation-duration: 5s; animation-iteration-count: 1; left: 0; height: 50%; width: 10px; position: absolute; bottom: 0; right: 0; margin: 0 auto; } #keyframes line{ 0%{ height: 0px; } 100%{ height: 50%; } }
SVG not displaying when the sidebar is closed
I have a sidebar that shows and hides content depending on the collapse status. Here is a LIVE JS FIDDLE Instead of using icons, I would like to use SVG images but if I use SVG images there is a jumpy effect during the transition and the SVG disappears when the sidebar is closed. What I've tried: .sidebar.close .nav-links li a .sidebarSvg{ opacity: 1; } I thought changing the opacity to 1 would do the job but I am doing something wrong. I also tried with display: block; but it did not work. Is my SVG wrong? UPDATE: I also tried placing the svg outside of the <a> but that makes the jumpy effect worst during the toggle transition.
try this : .sidebar.close .nav-links li .iocn-link { width:300px; } Now You can try thsi : let arrow = document.querySelectorAll(".arrow"); for (var i = 0; i < arrow.length; i++) { arrow[i].addEventListener("click", (e)=>{ let arrowParent = e.target.parentElement.parentElement;//selecting main parent of arrow arrowParent.classList.toggle("showMenu"); }); } let sidebar = document.querySelector(".sidebar"); let sidebarBtn = document.querySelector(".bx-menu"); console.log(sidebarBtn); sidebarBtn.addEventListener("click", ()=>{ sidebar.classList.toggle("close"); }); #import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;600;700&display=swap'); *{ margin: 0; padding: 0; box-sizing: border-box; font-family: 'Poppins', sans-serif; } .sidebarSvg{ margin-left: 15px; margin-right: 15px; } .sidebar{ position: fixed; top: 0; left: 0; height: 100%; width: 290px; background: #193D4C; z-index: 100; transition: all 0.5s ease; } .sidebar.close{ width: 78px; } .sidebar .logo-details{ height: 60px; width: 100%; display: flex; align-items: center; } .logo-icon{ margin-left: 15px; } .sidebar .logo-details i{ font-size: 30px; color: #fff; height: 50px; min-width: 78px; text-align: center; line-height: 50px; } .sidebar .logo-details .logo_name{ font-size: 22px; color: #fff; font-weight: 600; transition: 0.3s ease; transition-delay: 0.1s; margin-left:20px; } .sidebar.close .logo-details .logo_name{ transition-delay: 0s; opacity: 0; pointer-events: none; } .sidebar .nav-links{ height: 100%; padding: 30px 0 150px 0; overflow: auto; } .sidebar.close .nav-links{ overflow: visible; } .sidebar .nav-links::-webkit-scrollbar{ display: none; } .sidebar .nav-links li{ position: relative; list-style: none; transition: all 0.4s ease; } .sidebar .nav-links li:hover{ background: #193D4C; } .sidebar .nav-links li .iocn-link{ display: flex; align-items: center; justify-content: space-between; } .sidebar.close .nav-links li .iocn-link{ display: block; } .sidebar .nav-links li i{ height: 50px; min-width: 78px; text-align: center; line-height: 50px; color: #fff; font-size: 20px; cursor: pointer; transition: all 0.3s ease; } .sidebar .nav-links li.showMenu i.arrow{ transform: rotate(-180deg); } .sidebar.close .nav-links i.arrow{ display: none; } .sidebar .nav-links li a{ display: flex; align-items: center; text-decoration: none; } .sidebar .nav-links li a .link_name{ font-size: 18px; font-weight: 400; color: #fff; transition: all 0.4s ease; } .sidebar.close .nav-links li a .link_name{ opacity: 0; pointer-events: none; } .sidebar .nav-links li .sub-menu{ padding: 6px 6px 14px 80px; margin-top: -10px; background: #193D4C; display: none; } .sidebar .nav-links li.showMenu .sub-menu{ display: block; } .sidebar .nav-links li .sub-menu a{ color: #fff; font-size: 15px; padding: 5px 0; white-space: nowrap; opacity: 0.6; transition: all 0.3s ease; } .sidebar .nav-links li .sub-menu a:hover{ opacity: 1; } .sidebar.close .nav-links li .sub-menu{ position: absolute; left: 100%; top: -10px; margin-top: 0; padding: 10px 20px; border-radius: 0 6px 6px 0; opacity: 0; display: block; pointer-events: none; transition: 0s; } .sidebar.close .nav-links li:hover .sub-menu{ top: 0; opacity: 1; pointer-events: auto; transition: all 0.4s ease; } .sidebar .nav-links li .sub-menu .link_name{ display: none; } .sidebar.close .nav-links li .sub-menu .link_name{ font-size: 18px; opacity: 1; display: block; } .sidebar .nav-links li .sub-menu.blank{ opacity: 1; pointer-events: auto; padding: 3px 20px 6px 16px; opacity: 0; pointer-events: none; } .sidebar .nav-links li:hover .sub-menu.blank{ top: 50%; transform: translateY(-50%); } .sidebar .profile-details{ position: fixed; bottom: 0; width: 290px; display: flex; align-items: center; justify-content: space-between; background: #1d1b31; padding: 12px 0; transition: all 0.5s ease; } .sidebar.close .profile-details{ background: none; } .sidebar.close .profile-details{ width: 78px; } .sidebar .profile-details .profile-content{ display: flex; align-items: center; } .sidebar .profile-details img{ height: 52px; width: 52px; object-fit: cover; border-radius: 16px; margin: 0 14px 0 12px; background: #1d1b31; transition: all 0.5s ease; } .sidebar.close .profile-details img{ padding: 10px; } .sidebar .profile-details .profile_name, .sidebar .profile-details .job{ color: #fff; font-size: 18px; font-weight: 500; white-space: nowrap; } .sidebar.close .profile-details i, .sidebar.close .profile-details .profile_name, .sidebar.close .profile-details .job{ display: none; } .sidebar .profile-details .job{ font-size: 12px; } .home-section{ position: relative; background: #E4E9F7; height: 100vh; left: 290px; width: calc(100% - 260px); transition: all 0.5s ease; } .sidebar.close ~ .home-section{ left: 78px; width: calc(100% - 78px); } .home-section .home-content{ height: 60px; display: flex; align-items: center; } .home-section .home-content .bx-menu, .home-section .home-content .text{ color: #11101d; font-size: 35px; } .home-section .home-content .bx-menu{ margin: 0 15px; cursor: pointer; } .home-section .home-content .text{ font-size: 26px; font-weight: 600; } .userInitials { height: 38px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; width: 38px; text-align: center; vertical-align: middle; -moz-border-radius: 50%; -webkit-border-radius: 50%; border-radius: 50%; background: white; color: #193D4C; font-weight: 600; margin-bottom: 20px; margin-left: 20px; } #media (max-width: 420px) { .sidebar.close .nav-links li .sub-menu{ display: none; } } .dont-break { min-width: 100%; white-space: nowrap; overflow: hidden; } .centered-profile { display:inline-block; } .staff-position{ font-size: small !important; margin-top: 40px !important; } .staff-nav-holder { margin-left: 20px; } .sidebar.close .nav-links li .iocn-link { width:300px; } <!DOCTYPE html> <!-- Created by CodingLab |www.youtube.com/CodingLabYT--> <html lang="en" dir="ltr"> <head> <meta charset="UTF-8"> <!-- Boxiocns CDN Link --> <link href='https://unpkg.com/boxicons#2.0.7/css/boxicons.min.css' rel='stylesheet'> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <div class="sidebar close"> <div class="logo-details"> <div class="logo-icon"><svg xmlns="http://www.w3.org/2000/svg" width="43.878" height="44.07" viewBox="0 0 43.878 44.07"> <g id="g110" transform="translate(24.953 4.408)"> <path id="path4" d="M-8.04,26.725A10.416,10.416,0,0,1-12.112,12.6,10.437,10.437,0,0,1,.23,7.767L4.939-3.049a22.3,22.3,0,0,0-28.5,13.106A22.166,22.166,0,0,0-12.748,37.54Z" fill="#f8e3a9"/> <path id="path6" d="M6.523-2.315,1.815,8.5A10.417,10.417,0,0,1,5.887,22.623,10.438,10.438,0,0,1-6.455,27.459l-4.708,10.815a22.3,22.3,0,0,0,28.5-13.1A22.117,22.117,0,0,0,6.523-2.315" transform="translate(0.196 0.03)" fill="#f8e3a9"/> <path id="path8" d="M-3.265,8.85a8.525,8.525,0,0,1,8.525,8.525A8.525,8.525,0,0,1-3.265,25.9a8.525,8.525,0,0,1-8.525-8.526h0A8.608,8.608,0,0,1-3.265,8.85" transform="translate(0.187 0.189)" fill="#f8e3a9"/> </g> </svg> </div> <span class="logo_name dont-break">STACKOVERFLOW</span> </div> <ul class="nav-links"> <li> <div class="iocn-link"> <a href="#"> <span class="userInitials">JW</span> <div class="col-9 staff-nav-holder"> <span class="link_name dont-break centered-profile">John Walker</span> <span class="link_name staff-position">PM</span> </div> </a> <i class='bx bxs-chevron-down arrow centered-profile' ></i> </div> <ul class="sub-menu"> <li><a class="link_name" href="#">John Walker</a></li> <li>Customize your homepage</li> <li>Change your password</li> <li>Logout</li> </ul> </li> <li> <div class="iocn-link"> <a href="#"> <svg class="sidebarSvg" xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="white" viewBox="0 0 32 32"><g id="icon_layer" data-name="icon layer"><path class="cls-1" d="M20.5,12H16.55a.5.5,0,0,1-.5-.5.5.5,0,0,1,.5-.5H20.5a.51.51,0,0,1,.5.5A.5.5,0,0,1,20.5,12Z"/><path class="cls-1" d="M20.5,17H16.55a.5.5,0,0,1,0-1H20.5a.5.5,0,0,1,0,1Z"/><path class="cls-1" d="M20.5,22H16.55a.5.5,0,0,1,0-1H20.5a.5.5,0,0,1,0,1Z"/><path class="cls-1" d="M12.27,18h0a.49.49,0,0,1-.37-.18l-.8-1a.5.5,0,1,1,.76-.64l.44.52,1.44-1.58a.5.5,0,0,1,.74.67l-1.83,2A.51.51,0,0,1,12.27,18Z"/><path class="cls-1" d="M22.44,5.5H21.32a.5.5,0,0,0,0,1h1.12A1.07,1.07,0,0,1,23.5,7.56V24.44a1.07,1.07,0,0,1-1.06,1.06H9.56A1.07,1.07,0,0,1,8.5,24.44V7.56A1.07,1.07,0,0,1,9.56,6.5h1.22a.5.5,0,1,0,0-1H9.56A2.06,2.06,0,0,0,7.5,7.56V24.44A2.06,2.06,0,0,0,9.56,26.5H22.44a2.06,2.06,0,0,0,2.06-2.06V7.56A2.06,2.06,0,0,0,22.44,5.5Z"/><path class="cls-1" d="M12.37,7.73h7.27a.5.5,0,0,0,.5-.5V4.78a.5.5,0,0,0-.5-.5H18a2,2,0,0,0-3.88,0H12.37a.5.5,0,0,0-.5.5V7.23A.5.5,0,0,0,12.37,7.73Zm.5-2.45h1.66a.5.5,0,0,0,.5-.5,1,1,0,0,1,2,0,.5.5,0,0,0,.5.5h1.6V6.73H12.87Z"/><path class="cls-1" d="M11.09,11.83l.8,1a.53.53,0,0,0,.37.18h0a.48.48,0,0,0,.37-.17l1.83-2a.5.5,0,0,0-.74-.68l-1.44,1.58-.44-.52a.5.5,0,1,0-.76.64Z"/><path class="cls-1" d="M13.5,23h-2a.5.5,0,0,1-.5-.5v-2a.5.5,0,0,1,.5-.5h2a.5.5,0,0,1,.5.5v2A.5.5,0,0,1,13.5,23ZM12,22h1V21H12Z"/></g></svg> <span class="link_name">Projects</span> </a> <i class='bx bxs-chevron-down arrow' ></i> </div> <ul class="sub-menu"> <li><a class="link_name" href="#">Category</a></li> <li>Create a New Project</li> <li>See All Projects</li> </ul> </li> <li> <div class="iocn-link"> <a href="#"> <i class='bx bx-book-alt' ></i> <span class="link_name">Posts</span> </a> <i class='bx bxs-chevron-down arrow' ></i> </div> <ul class="sub-menu"> <li><a class="link_name" href="#">Posts</a></li> <li>Web Design</li> <li>Login Form</li> <li>Card Design</li> </ul> </li> <li> <a href="#"> <i class='bx bx-pie-chart-alt-2' ></i> <span class="link_name">Analytics</span> </a> </li> <li> <a href="#"> <i class='bx bx-menu'></i> <span class="link_name dont-break">Collapse sidebar</span> </a> </li> </ul> </div> <section class="home-section"> <div class="home-content"> <span class="text"></span> </div> </section> </body> </html>
Why is my NavBar's background not covering the last menu item?
Something on my website is bothering me. The last menu item of my Navbar is outside it's container's background: Here is how my CSS looks like: .nav-menu { display: flex; flex-direction: column; width: 100%; height: 280px; position: absolute; top: 80px; left: -100%; opacity: 1; transition: all 0.5s ease; align-items: space-evenly; } .nav-menu.active { display: flex; flex-direction: column; align-content: flex-start; background: #242222; left: 0; opacity: 1; transition: all 0.5s ease; z-index: 1; } .nav-links { text-align: center; padding: 2rem; width: 100%; display: table; } .nav-links:hover { background-color: #fff; color: #242424; border-radius: 0; } .navbar-logo { position: absolute; top: 0; left: 0; transform: translate(25%, 50%); } .menu-icon { display: block; position: absolute; top: 0; right: 0; transform: translate(-100%, 60%); font-size: 1.8rem; cursor: pointer; } .fa-times { color: #fff; font-size: 2rem; } .nav-links-mobile { display: block; text-align: center; margin: 2rem auto; border-radius: 4px; width: 80%; text-decoration: none; font-size: 1.5rem; background-color: transparent; color: #fff; padding: 14px 20px; border: 1px solid #fff; transition: all 0.3s ease-out; } .nav-links-mobile:hover { background: #fff; color: #242424; transition: 250ms; } } and HTML generated by a React component looks like this: <> <nav className='navbar'> <div className='navbar-container'> <Link to='/' className='navbar-logo' onClick={closeMobileMenu}> LOGO </Link> <div className='menu-icon' onClick={handleClick}> <i className={click ? 'fas fa-times' : 'fas fa-bars'} /> </div> <ul className={click ? 'nav-menu active' : 'nav-menu'}> <li className='nav-item'> <Link to='/' className='nav-links' onClick={closeMobileMenu}> Home </Link> </li> <li className='nav-item'> <HashLink to='/#wherewefly' onClick={closeMobileMenu} className='nav-links'> Where we fly </HashLink> </li> <li className='nav-item'> <Link to='/services' className='nav-links' onClick={closeMobileMenu} > Promotions </Link> </li> <li className='nav-item'> <Link to='/products' className='nav-links' onClick={closeMobileMenu} > Contact </Link> </li> </ul> {button && <Button buttonStyle='btn--outline'>LOGIN</Button>} </div> </nav> </> How can I make the last menu item (Contact) be covered by the black background too? I have tried changing the height but the menu items "follow" and are aligned to the bottom. I can't find out how to change it though. Edited: Picture has been updated
Remove height: 280px;. You are using flex-box so you shouldn't be setting the height or width attributes. The idea is to allow the box to be flexible to it's contents. If you want a fixed height you should be using flex-basis attribute. EXAMPLE I have had to convert your react to html to demonstrate but as you can see the code you provided works as expected. This would indicate the issue lies elsewhere in code you have not provided. .nav-menu { display: flex; flex-direction: column; width: 100%; position: absolute; top: 80px; left: -100%; opacity: 1; transition: all 0.5s ease; align-items: space-evenly; } .nav-menu.active { display: flex; flex-direction: column; align-content: flex-start; background: #242222; left: 0; opacity: 1; transition: all 0.5s ease; z-index: 1; } .nav-links { text-align: center; padding: 2rem; width: 100%; display: table; } .nav-links:hover { background-color: #fff; color: #242424; border-radius: 0; } .navbar-logo { position: absolute; top: 0; left: 0; transform: translate(25%, 50%); } .menu-icon { display: block; position: absolute; top: 0; right: 0; transform: translate(-100%, 60%); font-size: 1.8rem; cursor: pointer; } .fa-times { color: #fff; font-size: 2rem; } .nav-links-mobile { display: block; text-align: center; margin: 2rem auto; border-radius: 4px; width: 80%; text-decoration: none; font-size: 1.5rem; background-color: transparent; color: #fff; padding: 14px 20px; border: 1px solid #fff; transition: all 0.3s ease-out; } .nav-links-mobile:hover { background: #fff; color: #242424; transition: 250ms; } <nav class='navbar'> <div clas='navbar-container'> <a class='navbar-logo'> LOGO </a> <div class='menu-icon'> <i class='fas fa-times' /> </div> <ul class='nav-menu active'> <li class='nav-item'> <a class='nav-links'> Home </a> </li> <li class='nav-item'> <a class='nav-links'> Where we fly </a> </li> <li class='nav-item'> <a class='nav-links'> Promotions </a> </li> <li class='nav-item'> <a class='nav-links'> Contact </a> </li> </ul> <Button class='btn--outline'>LOGIN</Button> </div> </nav>
Well, the height is fixed in the CSS, if you want it to take the height the content has you need to use "fit-content".
Blockquote The issue could be the height of the nav-menu. please use min-hight instead. This may fix your issue .nav-menu { display: flex; flex-direction: column; width: 100%; min-height: 280px; position: absolute; top: 80px; left: -100%; opacity: 1; transition: all 0.5s ease; align-items: space-evenly; }
css is hover not working on class
I'm trying to get a bar to transition in when the li is hovered over however the hover seems to be ignored and nothing happens. If I instead put 'nav ul:hover', it works but the bar pops in under all the li's. <nav> <ul> <li class="nav-li">All Departments</li> <li class="nav-li">Shop by Room</li> <li class="nav-li">DIY Projects & Ideas</li> <li class="nav-li">Home Services</li> <li class="nav-li">Speacials & Offers</li> <li class="nav-li">Local Ad</li> </ul> </nav> CSS .nav-li { margin-right: 40px; display: inline-block; padding-bottom: 2em; transition: all .5s ease; cursor: pointer; position: relative; } .nav-li::after { content: ""; display: block; position: absolute; left: 0; bottom: 0; height: 3px; width: 0; transition: width .5s ease; } .nav-li:hover .nav-li::after { background-color: #f96302; width: 100%; }
The .nav-li:hover .nav-li::after should be .nav-li:hover::after .nav-li { margin-right: 40px; display: inline-block; padding-bottom: 2em; transition: all .5s ease; cursor: pointer; position: relative; } .nav-li::after { content: ""; display: block; position: absolute; left: 0; bottom: 0; height: 3px; width: 0; transition: width .5s ease; } .nav-li:hover::after { background-color: #f96302; width: 100%; } <nav> <ul> <li class="nav-li">All Departments</li> <li class="nav-li">Shop by Room</li> <li class="nav-li">DIY Projects & Ideas</li> <li class="nav-li">Home Services</li> <li class="nav-li">Speacials & Offers</li> <li class="nav-li">Local Ad</li> </ul> </nav>
Try combining the two. .nav-li:hover::after Example: https://jsfiddle.net/pc26LnLz/1/
Opacity on hover of parent is being transfered to submenu; how to prevent this using CSS
Right now the parent menu has an opacity shift on hover, this is being transferred to the sub menu (current & previous) as well. I want the sub menu to have a clear background so that the opacity band of the parent is the only thing that is visible. Is there a way to use an li class for the submenu that makes it exempt from the li class that is governing the parent. I've been trying different things but can't seem to make it work properly. Demo HTML <div> <ul id="mainmenu"> <li class="liHome"> <a class="maintextcolour" href="#item-x1y1" id="Home" rel= "none">INFO</a> </li> <li class="liServices"> <a class="maintextcolour" href="#item-x1y2" id="Services" rel= "SubMenuY2">EXHIBITIONS</a> <ul class="submenu" id="SubMenuY2"> <li class="sub1"> <a class="maintextcolour" href="#">CURRENT</a> </li> <li class="sub1"> <a class="maintextcolour" href="#">PREVIOUS</a> </li> </ul> </li> <li id="liEnvironment"> <a class="maintextcolour" href="#item-x1y3" id="Environment" rel="none">CV</a> </li> <li id="liCareer"> <a class="maintextcolour" href="#item-x1y4" id="Career" rel= "none">NEWS</a> </li> <li id="liContact"> <a class="maintextcolour" href="#item-x1y5" id="Contact" rel= "none">MORE</a> </li> </ul> </div> CSS: #charset UTF-8; /* CSS Document */ body { background-color: #666; background-size: 100%; background-repeat: no-repeat; } #mainmenu { margin: 0; padding: 0; list-style-type: none; position: relative; } #mainmenu li { clear: left; position: relative; } #mainmenu a { display: block; overflow: hidden; float: left; width: 100%; position: relative; opacity: 1; -webkit-transition: all .4s ease-in-out; padding-left: 20px; } #mainmenu li:hover a { background-position: 0 0; background-color: clear; background-color: rgba(255,255,255,0.5); width: 100%; opacity: 0; -webkit-transition: none; } #mainmenu li.active a { background-position: 0 0; background-color: clear; width: 100%; } .submenu { list-style-type: none; float: left; display: none; position: absolute; left: 135px; top: 0; width: auto; } #mainmenu li a:hover + .submenu,.submenu:hover { display: block; } .submenu li { display: inline-block; clear: none !important; } .submenu li a { float: right; margin-left: 10px; } .maintextcolour { font-family: Arial, Helvetica, sans-serif; font-size: 24px; color: #FFF; text-decoration: none; } .maintextcolour:hover { font-family: Arial, Helvetica, sans-serif; font-size: 24px; color: #0FF; text-decoration: none; } .headertext { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #FFF; text-decoration: none; }
Here is the updated Fiddle link. I have just added color to the following css: #mainmenu > li:hover > a { background-position: 0 0; background-color:clear; color:#0fffff; background-color:rgba(255,255,255,0.5); width:100%; \ opacity: 0; -webkit-transition: none; } Hope you want this.