I have an issue with styling a custom menu: when submenu is visible, the items should not be wider then the current parent item.
I've prepared a simple codepen example below and what I've tried is visible there, but still, the problem is this:
Also, only one submenu is visible at any point on real page if that accounts to anything. And "Longer submenu item" should wrap into two lines if longer then the parent item!
Basic HTML (printed dynamically otherwise of course):
<div id="menu">
<nav class="nav menu-inline" role="navigation">
<ul class="">
<li id="menu-item-68" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-68"><a href="#url">Main Menu item</a>
<ul class="sub-menu">
<li id="menu-item-171" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-171">
<a href="#section1">Longer submenu item</a>
</li>
<li id="menu-item-172" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-172">
<a href="#section2">Another submenu itm</a>
</li>
</ul>
</li>
<li id="menu-item-14" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-14">
<a href="#url2">2nd menu item</a>
<ul class="sub-menu">
<li id="menu-item-168" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-168">
<a href="#section1">short submenu</a>
</li>
<li id="menu-item-169" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-169">
<a href="#section2">short #2</a>
</li>
</ul>
</li>
<li>
<a href="#3">3rd main item</a>
</li>
</ul>
</nav>
</div>
And SASS:
/**
HOW TO ACHIEVE that "Longer submenu item" is aligned left with "Main Menu item" (if longer it should break into multiple lines). Of course all the text is dynamic and can be of any length..
*/
#menu {
max-width: 700px; // just to show what I mean easier
}
nav {
text-align: center;
font-size: 18px;
margin-bottom: 30px;
ul {
background: aqua;
list-style-type: none;
margin: 0;
padding: 0;
li {
text-align:left;
display: inline-block;
margin: 0 30px;
vertical-align: top; // need this (try on/off)
a {
color: black;
}
}
&.sub-menu {
text-align: left; // need this (try on/off)
margin-top: 15px;
li {
display: block;
margin-left:0; // need this (setting margin for all li above)
margin-right:0; // need this (setting margin for all li above)
}
}
}
}
How would you go about solving this, I'm a bit at a loss here :)