SVG not displaying when the sidebar is closed - css

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>

Related

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;
}

Issue with position and overlapping

I've came across an issue while coding my navigation bar. When I hover over a navigation bar element it shows correctly the submenu but the submenu should stay there also when mouse cursor hovers from the element to the submenu. This works correctly if there is no element next to the navigation bar element.
I think it will be easier to explain on an example.
When icon below magnifying glass is hovered it shows the submenu correctly however, when hovered over the submenu it disappears. This does not happen when you hover over the ID card and the corresponding submenu.
I figured out it has to do something with the CSS position element but Im unable to find a solution.
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
$($(".arrow").parent().parent().parent()).click(function(){
if (!$('.navbar2').hasClass('closed')){
$(this).toggleClass("showMenu")
}
})
$('.navbar2 .logoDetails a').click(function(){
$('.navbar2').toggleClass('closed')
})
$('.navbar2 .search a').click(function(){
if ($('.navbar2').hasClass('closed')){
$('.navbar2').toggleClass('closed')
}
$("#navBarSearch").focus();
})
$('#navBarSearch').on("input", function() {
const searchedValue = $(this).val()
$('.searchResults').empty()
if (searchedValue != '') {
let matches = new Array()
$('.link').each(function(){
const linkText = $(this).text()
if (linkText.toLowerCase().indexOf(searchedValue.toLowerCase()) >= 0 && jQuery.inArray(linkText.toLowerCase(), matches) === -1) {
matches.push(linkText.toLowerCase())
$('.searchResults').append(`<li class="searchResultsItem"><a href='${$(this).attr('href')}'>${linkText}</a></li>`)
}
})
}
})
});
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;600;700&display=swap');
:root {
--dark-primary-color: #11101d;
--dark-secondary-color: #1d1b31;
--dark-text-color: #f6f1d1;
--dark-hoverBG-color: #f6f1d1;
--dark-hoverTX-color: #11101d;
}
.navbar2 {
font-family: 'Poppins', sans-serif;
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 260px;
background: var(--dark-primary-color);
transition: all 0.5s ease;
}
.navbar2.closed,
.navbar2.closed .bottomBar {
width: 78px;
}
.navbar2 .logoDetails {
padding-top: 15px;
top: 0;
height: 50px;
width: 100%;
display: flex;
align-items: center;
}
.navbar2 .logoDetails a {
font-size: 30px;
color: var(--dark-text-color);
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
transition: all 0.5s ease;
}
.navbar2 .logoDetails a.collapseIcon {
font-size: 30px;
color: var(--dark-text-color);
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
transition: all 0.5s ease;
}
.navbar2 .logoDetails a.collapseIcon:hover {
background: var(--dark-hoverBG-color);
color: var(--dark-hoverTX-color);
}
.navbar2 .logoDetails .logoName {
font-size: 22px;
color: var(--dark-text-color);
font-weight: 600;
text-decoration: none;
margin-left: 10px;
}
.navbar2.closed .logoDetails .logoName {
display: none;
}
.navbar2 .navLinks {
background: var(--dark-primary-color);
height: 100%;
padding: 15px 0 210px 0;
overflow: auto;
padding-inline-start: 0px!important;
margin-bottom: 0px;
}
.navbar2.closed .navLinks {
overflow: visible;
}
.navbar2 .bottomBar .navLinks {
padding: 0;
}
.navbar2 .navLinks::-webkit-scrollbar {
display: none;
}
.navbar2 .navLinks li {
list-style: none;
position: relative;
transition: all 0.5s ease;
margin-left: 10px;
}
.navbar2.closed .navLinks li {
margin-left: 0px;
}
.navbar2 .navLinks li input {
position: relative;
height: 100%;
width: 100%;
top: 0;
left: 0;
border-radius: 12px;
outline: none;
border: none;
background: var(--dark-secondary-color);
padding-left: 60px;
font-size: 18px;
color: var(--dark-text-color);
transition: all 0.5s ease;
}
.navbar2.closed .navLinks li input {
display: none;
}
.navbar2 .navLinks li .fa-search {
position: absolute;
z-index: 99;
color: var(--dark-text-color);
font-size: 22px;
transition: all 0.5s ease;
}
.navbar2.closed .navLinks li .fa-search:hover {
background: var(--dark-hoverBG-color);
color: var(--dark-hoverTX-color);
}
.navbar2 .navLinks ul.searchResults {
position: absolute;
width: 100%;
padding-left: 0px;
border: 1px solid var(--dark-hoverTX-color);
}
.navbar2 .navLinks ul.searchResults .searchResultsItem {
padding: .75rem 1.25rem;
margin-left: 0px;
background-color: var(--dark-hoverBG-color);
border: 1px solid var(--dark-hoverTX-color);
border-radius: 6px 6px 6px 6px;
z-index: 1;
width: 100%;
}
.navbar2 .navLinks ul.searchResults .searchResultsItem a {
color: var(--dark-hoverTX-color);
}
.navbar2 .navLinks ul.searchResults .searchResultsItem:hover {
background-color: var(--dark-primary-color);
color: var(--dark-text-color);
border: 1px solid var(--dark-hoverBG-color);
}
.navbar2 .navLinks ul.searchResults .searchResultsItem:hover a {
color: var(--dark-text-color);
}
.navbar2.closed .navLinks ul.searchResults,
.navbar2.closed .navLinks ul.searchResults .searchResultsItem {
display: none;
}
.navbar2 .navLinks li:hover {
background: var(--dark-secondary-color);
}
.navbar2 .navLinks li .iconLink {
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
}
.navbar2 .navLinks li .iconLink.search {
height: 50px;
margin-bottom: 10px;
}
.navbar2 .navLinks li i {
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
color: var(--dark-text-color);
font-size: 20px;
transition: all 0.3s ease;
}
.navbar2 .navLinks li.showMenu i.arrow {
transform: rotate(-180deg);
}
.navbar2.closed .navLinks i.arrow {
display: none;
}
.navbar2 .navLinks li a {
display: flex;
align-items: center;
text-decoration: none;
}
.navbar2 .navLinks li .linkName {
font-size: 18px;
font-weight: 400;
color: var(--dark-text-color);
}
.navbar2 .navLinks li .subMenu {
padding-inline-start: 0px;
padding: 6px 0px 0px 78px;
margin-top: -10px;
background-color: var(--dark-secondary-color);
display: none;
transition: all 0.3s ease;
}
.navbar2 .navLinks li .subMenu li {
margin: 0px;
}
.navbar2 .navLinks li.showMenu .subMenu {
display: block;
transition: all 0.3s ease;
}
.navbar2 .navLinks li .subMenu a {
color: var(--dark-text-color);
font-size: 15px;
padding: 5px 0;
white-space: nowrap;
opacity: 0.6;
}
.navbar2 .navLinks li .subMenu a:hover {
opacity: 1;
}
.navbar2.closed .navLinks li a .linkName {
display: none;
}
.navbar2.closed .navLinks li .subMenu {
position: absolute;
left: 100%;
top: -10px;
margin-top: 0;
padding: 10px 20px;
border-radius: 0 6px 6px 0;
transition: all 0.5s ease;
opacity: 0;
display: block;
pointer-events: none;
z-index: 999;
}
.navbar2.closed .navLinks li:hover .subMenu {
top: 0;
opacity: 1;
pointer-events: auto;
}
.navbar2 .navLinks li .subMenu .linkName {
display: none;
}
.navbar2.closed .navLinks li .subMenu .linkName {
font-size: 18px;
opacity: 1;
display: block;
}
.navbar2 .navLinks li .subMenu.blank {
opacity: 0;
pointer-events: none;
}
.navbar2.closed .navLinks li:hover .subMenu.blank {
top: 50%;
transform: translateY(-50%);
display: block;
}
.navbar2 .bottomBar {
border-top: 1px solid var(--dark-text-color);
position: fixed;
bottom: 0;
width: 260px;
transition: all 0.5s ease;
}
.mainSection {
position: absolute;
left: 260px;
width: calc(100% - 260px);
transition: all 0.5s ease;
}
.navbar2.closed ~ .mainSection {
left: 78px;
width: calc(100% - 78px);
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.5.0/font/bootstrap-icons.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<div class="navbar2 closed">
<div class="logoDetails">
<i class="bi bi-list"></i>
<a href="{{ url_for('home.index') }}" class="logoName">
Test
</a>
</div>
<ul class="navLinks">
<li>
<div class="iconLink search">
<i class="fas fa-search"></i>
<input id="navBarSearch" type="text" placeholder="Search...">
</div>
<ul class="searchResults">
</ul>
</li>
<li>
<div class="iconLink">
<a href="#">
<i class="far fa-clone"></i>
<span class="linkName">Test1</span>
</a>
<i class="fas fa-chevron-down arrow"></i>
</div>
<ul class="subMenu">
<li><a class="linkName" href="#">Test1</a></li>
<li><a class="link" href="#">Test1.1</a></li>
<li><a class="link" href="#">Test1.2</a></li>
</ul>
</li>
<li>
<div class="iconLink">
<a href="#"><i class="fas fa-address-card"></i><span class="linkName">Test2</span>
</a>
<i class="fas fa-chevron-down arrow"></i>
</div>
<ul class="subMenu">
<li><a class="linkName" href="#">Test2</a></li>
<li><a class="link" href="#">Test2.1</a></li>
<li><a class="link" href="#">Test2.2</a></li>
</ul>
</li>
</ul>
<div class="bottomBar">
<ul class="navLinks">
<li>
<a href="#">
<i class="fas fa-bug"></i>
<span class="linkName">Report an issue</span>
</a>
<ul class="subMenu blank">
<li><a class="linkName" href="#">Report an issue</a></li>
</ul>
</li>
<li>
<a href="#">
<i class="fas fa-hammer"></i>
<span class="linkName">Feature request</span>
</a>
<ul class="subMenu blank">
<li><a class="linkName" href="#">Feature request</a></li>
</ul>
</li>
</ul>
</div>
</div>
<section class="mainSection">
<p> Test Text</p>
<p> Test Text</p>
<p> Test Text</p>
<p> Test Text</p>
<p> Test Text</p>
<p> Test Text</p>
</section>
The mainsection is being drawn above navbar2, so when you move the mouse over mainsection that will take the focus.
To solve this, you would just make sure the navbar2 is considered to be higher by putting something like z-index: 10000 into the CSS rules for that.
Like so:
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
$($(".arrow").parent().parent().parent()).click(function(){
if (!$('.navbar2').hasClass('closed')){
$(this).toggleClass("showMenu")
}
})
$('.navbar2 .logoDetails a').click(function(){
$('.navbar2').toggleClass('closed')
})
$('.navbar2 .search a').click(function(){
if ($('.navbar2').hasClass('closed')){
$('.navbar2').toggleClass('closed')
}
$("#navBarSearch").focus();
})
$('#navBarSearch').on("input", function() {
const searchedValue = $(this).val()
$('.searchResults').empty()
if (searchedValue != '') {
let matches = new Array()
$('.link').each(function(){
const linkText = $(this).text()
if (linkText.toLowerCase().indexOf(searchedValue.toLowerCase()) >= 0 && jQuery.inArray(linkText.toLowerCase(), matches) === -1) {
matches.push(linkText.toLowerCase())
$('.searchResults').append(`<li class="searchResultsItem"><a href='${$(this).attr('href')}'>${linkText}</a></li>`)
}
})
}
})
});
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;600;700&display=swap');
:root {
--dark-primary-color: #11101d;
--dark-secondary-color: #1d1b31;
--dark-text-color: #f6f1d1;
--dark-hoverBG-color: #f6f1d1;
--dark-hoverTX-color: #11101d;
}
.navbar2 {
font-family: 'Poppins', sans-serif;
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 260px;
background: var(--dark-primary-color);
transition: all 0.5s ease;
z-index: 10000; /*** ADDED THIS LINE ***/
}
.navbar2.closed,
.navbar2.closed .bottomBar {
width: 78px;
}
.navbar2 .logoDetails {
padding-top: 15px;
top: 0;
height: 50px;
width: 100%;
display: flex;
align-items: center;
}
.navbar2 .logoDetails a {
font-size: 30px;
color: var(--dark-text-color);
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
transition: all 0.5s ease;
}
.navbar2 .logoDetails a.collapseIcon {
font-size: 30px;
color: var(--dark-text-color);
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
transition: all 0.5s ease;
}
.navbar2 .logoDetails a.collapseIcon:hover {
background: var(--dark-hoverBG-color);
color: var(--dark-hoverTX-color);
}
.navbar2 .logoDetails .logoName {
font-size: 22px;
color: var(--dark-text-color);
font-weight: 600;
text-decoration: none;
margin-left: 10px;
}
.navbar2.closed .logoDetails .logoName {
display: none;
}
.navbar2 .navLinks {
background: var(--dark-primary-color);
height: 100%;
padding: 15px 0 210px 0;
overflow: auto;
padding-inline-start: 0px!important;
margin-bottom: 0px;
}
.navbar2.closed .navLinks {
overflow: visible;
}
.navbar2 .bottomBar .navLinks {
padding: 0;
}
.navbar2 .navLinks::-webkit-scrollbar {
display: none;
}
.navbar2 .navLinks li {
list-style: none;
position: relative;
transition: all 0.5s ease;
margin-left: 10px;
}
.navbar2.closed .navLinks li {
margin-left: 0px;
}
.navbar2 .navLinks li input {
position: relative;
height: 100%;
width: 100%;
top: 0;
left: 0;
border-radius: 12px;
outline: none;
border: none;
background: var(--dark-secondary-color);
padding-left: 60px;
font-size: 18px;
color: var(--dark-text-color);
transition: all 0.5s ease;
}
.navbar2.closed .navLinks li input {
display: none;
}
.navbar2 .navLinks li .fa-search {
position: absolute;
z-index: 99;
color: var(--dark-text-color);
font-size: 22px;
transition: all 0.5s ease;
}
.navbar2.closed .navLinks li .fa-search:hover {
background: var(--dark-hoverBG-color);
color: var(--dark-hoverTX-color);
}
.navbar2 .navLinks ul.searchResults {
position: absolute;
width: 100%;
padding-left: 0px;
border: 1px solid var(--dark-hoverTX-color);
}
.navbar2 .navLinks ul.searchResults .searchResultsItem {
padding: .75rem 1.25rem;
margin-left: 0px;
background-color: var(--dark-hoverBG-color);
border: 1px solid var(--dark-hoverTX-color);
border-radius: 6px 6px 6px 6px;
z-index: 1;
width: 100%;
}
.navbar2 .navLinks ul.searchResults .searchResultsItem a {
color: var(--dark-hoverTX-color);
}
.navbar2 .navLinks ul.searchResults .searchResultsItem:hover {
background-color: var(--dark-primary-color);
color: var(--dark-text-color);
border: 1px solid var(--dark-hoverBG-color);
}
.navbar2 .navLinks ul.searchResults .searchResultsItem:hover a {
color: var(--dark-text-color);
}
.navbar2.closed .navLinks ul.searchResults,
.navbar2.closed .navLinks ul.searchResults .searchResultsItem {
display: none;
}
.navbar2 .navLinks li:hover {
background: var(--dark-secondary-color);
}
.navbar2 .navLinks li .iconLink {
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
}
.navbar2 .navLinks li .iconLink.search {
height: 50px;
margin-bottom: 10px;
}
.navbar2 .navLinks li i {
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
color: var(--dark-text-color);
font-size: 20px;
transition: all 0.3s ease;
}
.navbar2 .navLinks li.showMenu i.arrow {
transform: rotate(-180deg);
}
.navbar2.closed .navLinks i.arrow {
display: none;
}
.navbar2 .navLinks li a {
display: flex;
align-items: center;
text-decoration: none;
}
.navbar2 .navLinks li .linkName {
font-size: 18px;
font-weight: 400;
color: var(--dark-text-color);
}
.navbar2 .navLinks li .subMenu {
padding-inline-start: 0px;
padding: 6px 0px 0px 78px;
margin-top: -10px;
background-color: var(--dark-secondary-color);
display: none;
transition: all 0.3s ease;
}
.navbar2 .navLinks li .subMenu li {
margin: 0px;
}
.navbar2 .navLinks li.showMenu .subMenu {
display: block;
transition: all 0.3s ease;
}
.navbar2 .navLinks li .subMenu a {
color: var(--dark-text-color);
font-size: 15px;
padding: 5px 0;
white-space: nowrap;
opacity: 0.6;
}
.navbar2 .navLinks li .subMenu a:hover {
opacity: 1;
}
.navbar2.closed .navLinks li a .linkName {
display: none;
}
.navbar2.closed .navLinks li .subMenu {
position: absolute;
left: 100%;
top: -10px;
margin-top: 0;
padding: 10px 20px;
border-radius: 0 6px 6px 0;
transition: all 0.5s ease;
opacity: 0;
display: block;
pointer-events: none;
z-index: 999;
}
.navbar2.closed .navLinks li:hover .subMenu {
top: 0;
opacity: 1;
pointer-events: auto;
}
.navbar2 .navLinks li .subMenu .linkName {
display: none;
}
.navbar2.closed .navLinks li .subMenu .linkName {
font-size: 18px;
opacity: 1;
display: block;
}
.navbar2 .navLinks li .subMenu.blank {
opacity: 0;
pointer-events: none;
}
.navbar2.closed .navLinks li:hover .subMenu.blank {
top: 50%;
transform: translateY(-50%);
display: block;
}
.navbar2 .bottomBar {
border-top: 1px solid var(--dark-text-color);
position: fixed;
bottom: 0;
width: 260px;
transition: all 0.5s ease;
}
.mainSection {
position: absolute;
left: 260px;
width: calc(100% - 260px);
transition: all 0.5s ease;
}
.navbar2.closed ~ .mainSection {
left: 78px;
width: calc(100% - 78px);
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.5.0/font/bootstrap-icons.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<div class="navbar2 closed">
<div class="logoDetails">
<i class="bi bi-list"></i>
<a href="{{ url_for('home.index') }}" class="logoName">
Test
</a>
</div>
<ul class="navLinks">
<li>
<div class="iconLink search">
<i class="fas fa-search"></i>
<input id="navBarSearch" type="text" placeholder="Search...">
</div>
<ul class="searchResults">
</ul>
</li>
<li>
<div class="iconLink">
<a href="#">
<i class="far fa-clone"></i>
<span class="linkName">Test1</span>
</a>
<i class="fas fa-chevron-down arrow"></i>
</div>
<ul class="subMenu">
<li><a class="linkName" href="#">Test1</a></li>
<li><a class="link" href="#">Test1.1</a></li>
<li><a class="link" href="#">Test1.2</a></li>
</ul>
</li>
<li>
<div class="iconLink">
<a href="#"><i class="fas fa-address-card"></i><span class="linkName">Test2</span>
</a>
<i class="fas fa-chevron-down arrow"></i>
</div>
<ul class="subMenu">
<li><a class="linkName" href="#">Test2</a></li>
<li><a class="link" href="#">Test2.1</a></li>
<li><a class="link" href="#">Test2.2</a></li>
</ul>
</li>
</ul>
<div class="bottomBar">
<ul class="navLinks">
<li>
<a href="#">
<i class="fas fa-bug"></i>
<span class="linkName">Report an issue</span>
</a>
<ul class="subMenu blank">
<li><a class="linkName" href="#">Report an issue</a></li>
</ul>
</li>
<li>
<a href="#">
<i class="fas fa-hammer"></i>
<span class="linkName">Feature request</span>
</a>
<ul class="subMenu blank">
<li><a class="linkName" href="#">Feature request</a></li>
</ul>
</li>
</ul>
</div>
</div>
<section class="mainSection">
<p> Test Text</p>
<p> Test Text</p>
<p> Test Text</p>
<p> Test Text</p>
<p> Test Text</p>
<p> Test Text</p>
</section>

Make a ::after element the same size and position as a flex child element

I am trying to add an efficient box-shadow to my flex elements by following this article.
Problem is it doesn't work, this is the minified example.
I've tried setting the position: relative on nav, but it just made the ::after element the size of the whole navbar.
<nav>
<div class="nav-left">
<a href="#">
hello
</a>
</div>
<div class="nav-center"></div>
<div class="nav-right"></div>
</nav>
nav {
display: flex;
min-height: 5rem;
background-color: #402424;
align-items: stretch;
}
nav a,
nav .brand {
text-decoration: none;
align-items: center;
display: flex;
color: #AFAFAF;
}
nav a::after {
content: '';
position: absolute;
z-index: -1;
width: 100%;
height: 100%;
opacity: 0;
border-radius: 5px;
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
transition: opacity 0.3s ease-in-out;
}
nav a:hover::after {
opacity: 1;
}
Try this instead,
Add to nav a
nav a{position:relative;}
also add to nav a::after
nav a::after{
top:0;
right:0;
left:0;
bottom:0;
}
body {
background: #20262E;
padding: 0;
margin: 0;
font-family: Helvetica;
}
nav {
display: flex;
min-height: 5rem;
background-color: #402424;
align-items: stretch;
}
nav a,
nav .brand {
text-decoration: none;
align-items: center;
display: flex;
color: #AFAFAF;
position:relative;
}
nav a::after {
content: '';
position: absolute;
z-index: 1;
opacity: 0;
top:0;
right:0;
left:0;
bottom:0;
border-radius: 5px;
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
transition: opacity 0.3s ease-in-out;
}
nav a:hover::after {
opacity: 1;
}
.nav-left,
.nav-center,
.nav-right {
display: flex;
flex: 1;
}
.nav-left {
justify-content: flex-start;
}
.nav-center {
justify-content: center;
}
.nav-right {
justify-content: flex-end;
}
<nav>
<div class="nav-left">
<a href="#">
hello
</a>
</div>
<div class="nav-center">
</div>
<div class="nav-right">
World
</div>
</nav>

I face some position problems in css

lately I've started coding with some css and html and I decided to make my own first website, so I had some problems in changing the position of a div containing two buttons("s'inscrire" and "se connecter") ... Also when I hover on the header list, it starts moving upwards and downwards, I changed the padding, the margin... But nothing happens!
#import url('https://fonts.googleapis.com/css?family=Montserrat|Raleway');
*{
margin:0;
padding: 0;
font-family: Raleway;
}
body{
background: linear-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0.4)),
url('1.jpg');
background-position: center;
background-size: cover;
height: 100vh;
}
.main ul{
float: right;
display: block;
list-style-type: none;
font-size: 15px;
margin-top: 20px;
position: sticky;
}
.main ul li{
display: inline-block;
width: 150px;
}
.main ul li i{
padding-right: 5px;
color: #eccc68;
opacity: 0.6;
}
.main ul li a{
text-decoration: none;
color: #fff;
padding: 5px 20px;
border: 1px solid transparent;
border-radius: 7px;
}
.main ul li a:hover{
position: relative;
display: block;
background-color: #fff;
color: #000;
transition: 0.6s ease;
}
.main ul li.active a{
background-color: #fff;
color: #000;
}
.main ul ul li{
list-style-type: none;
display: none;
}
.main ul li:hover ul li{
display: block;
}
.login ul{
float: right;
position: fixed;
list-style-type: none;
display: inline-block;
font-size: 12px;
}
.logo img{
float: left;
width: 150px;
height: auto;
margin-top: 15px;
margin-left: 0;
}
header{
background-color: rgba(202, 211, 200,0.6);
}
.main{
max-width: 1200px;
margin: auto;
}
.title img{
width: 40%;
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%,-100%);
}
.title p{
width: 40%;
position: absolute;
top: 54%;
left: 50%;
font-size: 25px;
font-family: Montserrat;
font-weight: lighter;
transform: translate(-50%,-100%);
text-align: center;
color: #F8EFBA;
}
.button{
position: absolute;
top: 60%;
left: 50%;
transform: translate(-50%,-100%);
}
.button a i{
padding-right: 5px;
color: #eccc68;
opacity: 0.6;
}
.btn{
border: 1px solid #eccc68;
border-radius: 15px;
padding: 10px 30px;
color: #fff;
font-size: 20px;
text-decoration: none;
}
.btn:hover{
background-color: #fff;
color: #000;
transition: 0.6s ease;
}
.footer{
width: 100%;
position: fixed;
bottom: 0;
background-color: rgba(0,0,0,0.4);
height: 60px;
}
.footer ul{
transform: translateX(1800px);
margin-right: 0px;
list-style-type: none;
font-size: 15px;
margin-top: 20px;
}
.footer ul li a i{
font-size: 20px;
padding-right: 5px;
color: #eccc68;
}
.footer ul li{
display: inline-block;
}
.footer h5{
font-size: 11px;
color: #eccc68;
text-align: center;
opacity: 0.7;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Trip Buddy | Your free online travel guide</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="shortcut icon" type="image/png" href="favicon.ico">
</head>
<body>
<header>
<div class="main">
<div class="logo">
<img src="2.png">
</div>
<ul>
<li class="active"><i class="fas fa-home"></i>Accueil</li>
<li><i class="fas fa-city"></i>Villes dispo
<ul>
<li>Marrakech</li>
<li>Rabat</li>
<li>Tanger</li>
<li>Essaouira</li>
</ul>
</li>
<li><i class="fas fa-hand-holding"></i>Services</li>
<li><i class="fas fa-user-alt"></i>Contact</li>
</ul>
</div>
<div class="login">
<ul>
<li>S'inscrire</li>
<li>Se connecter</li>
</ul>
</div>
<div class="title">
<img src="2.png">
<p>Trip Buddy est ton premier accompagnant guide en ligne. Rejoignez notre nombreuse communauté et télecharger l'application sur toutes les platformes GRATUITEMENT!</p>
</div>
<div class="button">
<i class="far fa-play-circle"></i>Regarder video
<i class="far fa-question-circle"></i>Aide
</div>
</header>
<footer>
<div class="footer">
<ul>
<li><i class="fab fa-facebook"></i></li>
<li><i class="fab fa-twitter-square"></i></li>
<li><i class="fab fa-instagram"></i></li>
<li><i class="fab fa-snapchat-square"></i></li>
</ul>
<h5>
©Khalil 2019
</h5>
</div>
</footer>
</body>
</html>
Please if you can fix this problem I'm gonna be so grateful for your help. Thanks.
I have Changed the following CSS code and menu now fixed.
.main ul li a{
text-decoration: none;
color: #fff;
padding: 5px 20px;
border: 1px solid transparent;
border-radius: 7px;
position: relative;
display: block;
transition:all 0.6s ease; /* this will be always at normal stage not at hover*/
}
.main ul li a:hover{
background-color: #fff;
color: #000;
}
Please have a look at this at codepen
#import url('https://fonts.googleapis.com/css?family=Montserrat|Raleway');
*{
margin:0;
padding: 0;
font-family: Raleway;
}
body{
background: linear-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0.4)),
url('1.jpg');
background-position: center;
background-size: cover;
height: 100vh;
}
.main ul{
float: right;
display: block;
list-style-type: none;
font-size: 15px;
margin-top: 20px;
position: sticky;
}
.main ul li{
display: inline-block;
width: 150px;
}
.main ul li i{
padding-right: 5px;
color: #eccc68;
opacity: 0.6;
}
.main ul li a{
text-decoration: none;
color: #fff;
padding: 5px 20px;
border: 1px solid transparent;
border-radius: 7px;
position: relative;
display: block;
transition:all 0.6s ease; /* this will be always at normal stage not at hover*/
}
.main ul li a:hover{
background-color: #fff;
color: #000;
}
.main ul li.active a{
background-color: #fff;
color: #000;
}
.main ul ul li{
list-style-type: none;
display: none;
}
.main ul li:hover ul li{
display: block;
}
.login ul{
float: right;
position: fixed;
list-style-type: none;
display: inline-block;
font-size: 12px;
}
.logo img{
float: left;
width: 150px;
height: auto;
margin-top: 15px;
margin-left: 0;
}
header{
background-color: rgba(202, 211, 200,0.6);
}
.main{
max-width: 1200px;
margin: auto;
}
.title img{
width: 40%;
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%,-100%);
}
.title p{
width: 40%;
position: absolute;
top: 54%;
left: 50%;
font-size: 25px;
font-family: Montserrat;
font-weight: lighter;
transform: translate(-50%,-100%);
text-align: center;
color: #F8EFBA;
}
.button{
position: absolute;
top: 60%;
left: 50%;
transform: translate(-50%,-100%);
}
.button a i{
padding-right: 5px;
color: #eccc68;
opacity: 0.6;
}
.btn{
border: 1px solid #eccc68;
border-radius: 15px;
padding: 10px 30px;
color: #fff;
font-size: 20px;
text-decoration: none;
}
.btn:hover{
background-color: #fff;
color: #000;
transition: 0.6s ease;
}
.footer{
width: 100%;
position: fixed;
bottom: 0;
background-color: rgba(0,0,0,0.4);
height: 60px;
}
.footer ul{
transform: translateX(1800px);
margin-right: 0px;
list-style-type: none;
font-size: 15px;
margin-top: 20px;
}
.footer ul li a i{
font-size: 20px;
padding-right: 5px;
color: #eccc68;
}
.footer ul li{
display: inline-block;
}
.footer h5{
font-size: 11px;
color: #eccc68;
text-align: center;
opacity: 0.7;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Trip Buddy | Your free online travel guide</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="shortcut icon" type="image/png" href="favicon.ico">
</head>
<body>
<header>
<div class="main">
<div class="logo">
<img src="2.png">
</div>
<ul>
<li class="active"><i class="fas fa-home"></i>Accueil</li>
<li><i class="fas fa-city"></i>Villes dispo
<ul>
<li>Marrakech</li>
<li>Rabat</li>
<li>Tanger</li>
<li>Essaouira</li>
</ul>
</li>
<li><i class="fas fa-hand-holding"></i>Services</li>
<li><i class="fas fa-user-alt"></i>Contact</li>
</ul>
</div>
<div class="login">
<ul>
<li>S'inscrire</li>
<li>Se connecter</li>
</ul>
</div>
<div class="title">
<img src="2.png">
<p>Trip Buddy est ton premier accompagnant guide en ligne. Rejoignez notre nombreuse communauté et télecharger l'application sur toutes les platformes GRATUITEMENT!</p>
</div>
<div class="button">
<i class="far fa-play-circle"></i>Regarder video
<i class="far fa-question-circle"></i>Aide
</div>
</header>
<footer>
<div class="footer">
<ul>
<li><i class="fab fa-facebook"></i></li>
<li><i class="fab fa-twitter-square"></i></li>
<li><i class="fab fa-instagram"></i></li>
<li><i class="fab fa-snapchat-square"></i></li>
</ul>
<h5>
©Khalil 2019
</h5>
</div>
</footer>
</body>
</html>

menu in css - dropdown menu

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.

Resources