I'm currently working on a drop-down menu, but I'm facing an issue where adding position: absolute;
and display: block;
is causing the second ul
element to not be fully visible. My goal is to have both ul
elements visible so that I can proceed to incorporate a hover
effect and adjust the display to complete the drop-down menu.
I've attempted to use z-index
and overflow
, however, neither solution has proven successful.
/* CSS code snippet */
/* Import Google Fonts */
@import url("https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@100;200;300;400;500;600;700;800;900&display=swap");
* {
/* Reset default margin,padding and box-sizing */
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
text-decoration: none;
font-family: 'Roboto Slab', serif;
}
html {
font-size: 10px;
}
/* Custom styling for body */
body {
background-color: #1C1B1A;
}
ul {
list-style: none;
}
a {
text-decoration: none;
color: #fff;
}
h1,
h2,
h3 {
color: #fff;
}
/* Custom styling for header navigation */
header nav {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
position: relative;
width: 100%;
font-size: 2rem;
}
header nav h1 {
font-size: 3.5rem;
font-weight: 350;
text-transform: uppercase;
padding-left: 5rem;
}
/* Custom styling for navigation links */
header nav .links {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
background: #6B653C;
height: 100%;
padding: 1rem;
padding-left: 5rem;
padding-right: 5rem;
-webkit-clip-path: polygon(2.75rem 0, 100% 0, 100% 100%, 0 100%);
clip-path: polygon(2.75rem 0, 100% 0, 100% 100%, 0 100%);
}
header nav .links ul {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
header nav .links ul li {
margin: 1rem;
text-transform: uppercase;
position: relative;
}
header nav .links ul li ul {
display: block;
position: absolute;
top: 2.2rem;
background: #6B653C;
}
header nav .links ul li ul li {
margin-left: 0;
color: #ffffff;
}
<body>
<header>
<nav>
<h1>logo</h1>
<div class="links">
<ul>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a>
<ul>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul>
</li>
<li><a href="#"><i class="fas fa-user"></i></a></li>
</ul>
</div>
</nav>
</header>
</body>
Feel free to check out the code on Codepen: https://codepen.io/ji-nov-ek/pen/KKWMawG