Archived topic
sidebar nav menu evenly space horizontal lines for sub menu
5 replies · Started by Stephen on July 1, 2022
Hi, I've used the CSS below to add a horizontal line between menu items in sidebar.
Works great except the sub menu items mess up the line spacing.
If I make sub menu items not sub then lines are OK but I prefer to have them sub menu to keep indented.
How can I get evenly spaced lines between all menu items including sub menu please ?
.sidebar .widget_nav_menu ul li {
border-bottom: 1px solid lightgray;
padding-bottom:10px;
padding-top:10px;
}
Hi Stephen,
I don't really see a good way to do that.
What if we only apply the CSS to parent menu items like this?
.sidebar .widget_nav_menu ul:not(.sub-menu) > li {
border-bottom: 1px solid lightgray;
padding-bottom: 10px;
padding-top: 10px;
}
Hi, no I prefer evenly spaced lines.
If I set the menu so there is no sub menu items can I use CSS to indent some of the menu items ?
Hi there,
remove your CSS and add this:
.sidebar .widget_nav_menu ul li {
margin-bottom: 0;
}
.sidebar .widget_nav_menu ul li a {
display: block;
padding-top: 0.5em;
padding-bottom: 0.5em;
border-bottom: 1px solid lightgray;
}
if you wand the sub menu borders to span the width of the parent items then add this too:
.sidebar .widget_nav_menu ul.sub-menu {
margin-left: 0;
}
.sidebar .widget_nav_menu ul.sub-menu li a {
padding-left: 1em;
}
Thats amazing - Thank you 👍
You're welcome