I’m currently trying to make a header that has a transparent background (something like rgba(0,0,0,0.8)
and when clicking on a burger menu, I should display a submenu.
The trick is, I want to add a slide-in effect on the submenu, so it should translate from behind the header until it’s fully visible. The issue is that, as the header is a bit transparent, the submenu is visible behind the header and I don’t know how I could do to hide the submenu when it’s behind the header, but make it visible when it’s outside the header.
body {
padding: 0;
margin: 0;
}
.header {
background-color: rgba(0, 0, 0, 0.8);
position: fixed;
top: 0;
left: 0;
width: -webkit-fill-available;
max-width: 100vw;
height: 100px;
display: flex;
align-items: center;
justify-content: flex-end;
padding: 0 4em;
z-index: 1000;
}
.header p {
color: white;
z-index: 750;
}
.submenu {
position: absolute;
right: 0;
top: 0;
width: 100px;
background-color: rgba(0, 0, 0, 0.8);
transition: all 1s linear;
z-index: 0;
}
.submenu ul {
display: none;
flex-direction: column;
row-gap: 1em;
color: white;
}
.header p:hover ~ .submenu {
transform: translateY(100px);
}
.header p:hover ~ .submenu ul {
display: flex;
}
<div class="header">
<p>Hover me!</p>
<div class="submenu">
<ul>
<li>Lien</li>
<li>Lien</li>
<li>Lien</li>
</ul>
</div>
</div>
3
Answers
You can get the desired effect you want I believe by:
Removing the various "z-indexes" for all elements, but keeping a negative z-index for the sub-menu class selector.
Adding "position: relative" to the header class.
Changing the background color to greyscale instead of opacity: "background-color: #333333"
Apply the translation on the
ul
element and you can use clip-path on thesubmenu
to simulate an "overflow: hidden" only from the topWhatever you try to perform on
.submenu
class, perform same action on.submenu ul
, apply transform css on.submenu ul
as below