I am trying to make a simple navbar I managed to make the base but when I try to personalize I am getting stuck.
My objective is that when the mouse goes over each element(home, etc) it highlights like a box, but currently it only highlights the <a>
I tried and not the <li>
holding it.
I’m trying to make the <li>
an anchor that can be clicked and highlighted similar to stack’s navbar.
.nav-top {
background: rgb(151, 138, 63);
margin: 0;
padding: 1rem 0;
display: flex;
justify-content: flex-end;
align-items: center;
}
.nav-item {
list-style: none;
margin-right: 1.2rem;
padding: 5px 10px;
}
.nav-top ul {
margin: 0 auto;
padding: 0;
list-style: none
}
.nav-top li:hover {
display: block
}
.nav-top a:hover {
background: #F2F2F2;
color: #444444;
}
.nav-item a {
text-decoration: none;
color: white;
width: 100px;
}
.nav-item:first-child {
margin-right: auto;
margin-left: 2rem;
}
.nav-item a:hover {
color: aqua;
}
<navbar>
<ul class="nav-top">
<li class="nav-item"><label class="logo">LoremX</label></li>
<li class="nav-item"><a href="index.html">Home</a></li>
<li class="nav-item"><a href="#">About</a></li>
<li class="nav-item" id="contact"><a href="#">Contact</a></li>
</ul>
</navbar>
2
Answers
just add padding and a border in an anchor element
The only
:hover
declaration you have forli
is the default value ofdisplay: block
. The color change declarations are made only fora
Not related to the hover effect, just correcting your markup:
.nav-top ul
selector but the example doesn’t include a nestedul
label
element.navbar
is not an HTML element and I suspect you wantnav