Have you ever tried cloning a navbar? Take a look at this example: navbar
If you hover over a section like "BOOK," you'll notice an orange rectangle that appears above the navbar. This div (orange) is positioned between the black background of the navbar and the text.
I believe this effect is achieved using a div, but I've had trouble recreating it myself. Whenever I add a Sibling Element after the .list-item div and then hover over it, the text 'BOOK' becomes obscured because that div is positioned higher in the layout compared to the .list-item div.
body {
margin: 0;
padding: 0;
font-family: Roboto, sans-serif;
}
header {
text-align: center;
padding-bottom: 3rem;
}
nav {
width: 100%;
display: flex;
justify-content: center;
margin: 0 auto;
color: white;
background: black;
}
ul {
margin: 0;
padding: 0;
display: flex;
width: 85%;
font-weight: 600;
}
li {
list-style-type: none;
cursor: pointer;
padding: 0 1.6rem;
line-height: 3;
}
li:hover {
background-color: tomato;
transition: 220ms ease;
}
.list-item span {
padding-right: 0.4rem;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<header>
<h3>
E-SHOP
</h3>
</header>
<nav>
<ul>
<li>
<div class="list-item">
<span>HOME</span>
<i class="fas fa-angle-down"></i>
</div>
</li>
<li>
<div class="list-item">
<span>BOOK</span>
<i class="fas fa-angle-down"></i>
</div>
</li>
<li>
<div class="list-item">
<span>AUDIO BOOKS</span>
<i class="fas fa-angle-down"></i>
</div>
</li>
<li>
<div class="list-item">
<span>CHILDREN'S BOOKS</span>
<i class="fas fa-angle-down"></i>
</div>
</li>
<li>
<div class="list-item">
<span>BLOG</span>
<i class="fas fa-angle-down"></i>
</div>
</li>
<li>
<div class="list-item">
<span>PAGES</span>
<i class="fas fa-angle-down"></i>
</div>
</li>
<li>
<div class="list-item">
<span>SALES OFF</span>
<i class="fas fa-angle-down"></i>
</div>
</li>
</ul>
</nav>
</body>
</html>