Reputation: 33
I am trying to create drop-down menu, but when I add position: absolute;
and display: block;
, I can't see all of the second ul
element . I want to see both ul
elements, so I can then add a hover
and a display
and complete the drop-down menu.
I tried using z-index
and overflow
, but nothing worked.
@import url("https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@100;200;300;400;500;600;700;800;900&display=swap");
* {
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;
}
body {
background-color: #1C1B1A;
}
ul {
list-style: none;
}
a {
text-decoration: none;
color: #fff;
}
h1,
h2,
h3 {
color: #fff;
}
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;
}
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>
Codepen: https://codepen.io/ji-nov-ek/pen/KKWMawG
Upvotes: 0
Views: 88
Reputation: 4153
Below is a simplified code, because yours is a big mess ;)
You're making the code too complicated. For example, use the wrong font-weight: 350
fonts, but there are only hundreds in googleapis.com
decalaration.
And why do you need so many versions of the fonts, [100,200, ..., 900] after all, it slows down the page incredibly. You can use html strong
or b
elements.
:root {
--olive: #6b653c;
}
@import url("https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@100;200;300;400;500;600;700;800;900&display=swap");
*,
:after,
:before {
box-sizing: border-box;
}
html {
height: 100%;
}
body {
background-color: #1c1b1a;
text-decoration: none;
margin: 0;
font-size: 1rem;
font-family: "Roboto Slab", serif;
}
ul {
list-style: none;
padding: 0;
}
a {
text-decoration: none;
color: #fff;
}
h1,
h2,
h3 {
color: #fff;
}
header {
height: 78px;
}
nav {
display: flex;
align-items: center;
}
h1 {
font-size: 2.5rem;
font-weight: 500;
text-transform: uppercase;
padding-left: 40px;
margin: 0;
}
.links {
position: relative;
margin-left: auto;
background: var(--olive);
padding-right: 20px;
}
.links:before {
content: "";
position: absolute;
left: -30px;
border-right: 0px solid transparent;
border-left: 30px solid transparent;
border-bottom: 50px solid var(--olive);
}
.links ul li {
display: inline-block;
position: relative;
font-size: 1rem;
text-transform: uppercase;
}
.links ul li {
margin-left: 20px;
}
.sub-menu ul {
display: none;
position: absolute;
left: -20px;
background: var(--olive);
padding: 10px 20px;
}
.sub-menu ul li {
margin: 0;
}
.sub-menu:hover ul {
display: block;
}
<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 class="sub-menu"><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>last</a></li>
</ul>
</div>
</nav>
</header>
Upvotes: 1