I know there's a pic about pseudo elements' own relationship.
(from CSS tricks)
I met a problem about this, where I'd like to make .nav-box
's white background-color in front of .nav-box::after
's black one, as a floating menu list. Though I'd seen this from previous question, it seems to be impossible to make the above work. Would like to check if so.
Code is also on JSBIN.
body {
position: relative;
z-index: 1;
}
.nav-box {
position: relative;
z-index: 50; /* no effects */
top: 0;
right: 0;
width: 60vw;
height: 100vh;
border: 1px solid red;
background-color: white;
}
.nav-box::after {
position: absolute;
z-index: -1;
content:"";
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: black;
}
.nav-box::before {
/* this will be a menu button */
position: absolute;
z-index: 10;
right: 0;
content: "O";
color: orange;
font-size: 40px;
}
<body>
<nav class="nav-box">
<ul class="menu-box">
<li><a href="">About</a></li>
<li><a href="">Blog</a></li>
<li><a href="">Contact</a></li>
</ul>
</nav>
</body>