Answer the question
In order to leave comments, you need to log in
CSS Sidebar - how to keep the tree view and make the selection of the entire line (ignoring indentation)?
How to make a garden bar in the form of a tree with (i.e. the descendant menu should recede from the edge by a greater distance than the parent) and at the same time a:hover
select the entire line (and not the part where it starts <a>
)
Example at jsfiddle.net
<span>Sidebar</span>
<div id="sidebar">
<ul>
<li class="nav-item">
<a href="#" class="nav-link">One item</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Two item</a>
</li>
<ul class="submenu">
<li class="nav-item">
<a href="#" class="nav-link">Submenu one item</a>
</li>
<ul class="submenu">
<li class="nav-item">
<a href="#" class="nav-link">Submenu one item</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Submenu two item</a>
</li>
</ul>
<li class="nav-item">
<a href="#" class="nav-link">Submenu two item</a>
</li>
</ul>
</ul>
</div>
#sidebar {
background: #e8e8ee;
width: 300px;
ul {
list-style: none;
}
.nav-link {
display: block;
line-height: 40px;
text-decoration: none;
&:hover {
background: green;
}
}
}
Answer the question
In order to leave comments, you need to log in
You can try pseudo-elements
ul{
padding-left:20px;
}
li{
position:relative;
}
a:hover:after{
content:'';
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
background:green;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question