I was working on a vertical menu navigation but when the menu is hovered the vertical line doesn’t slide on the right place. Also, when it’s clicked the vertical line won’t stay. Does anyone have a solution for these bugs?
function selectNav(get_this){
$('#sticky li').removeClass('selected');
get_this.classList.add('selected');
}
.in-page-menu > .in-page-menu li{
line-height: 2em;
height: 2em;
}
.in-page-menu > .in-page-menu li > .in-page-menu li a {
display: block;
padding: 0 2em;
}
.in-page-menu li:last-child::after, li.selected::after {
content: "";
position: absolute;
background: rgba(255, 99, 71, 0.6);
height: 2.5em;
margin-top: 15px;
left: 40px;
width: .2em;
top: 0;
transition: all ease-in-out .2s;
right: 0;
}
.in-page-menu li.selected::after{
transform: translateY(-2.5em);
}
.in-page-menu li:nth-child(1):hover ~ li:last-child::after {
transform:translateY(0.5em) !important;
}
.in-page-menu li:nth-child(2):hover ~ li:last-child::after {
transform:translateY(83px) !important;
}
.in-page-menu li:nth-child(2).selected ~ li:last-child::after {
transform:translateY(83px) !important;
}
.in-page-menu li:nth-child(3):hover ~ li:last-child::after {
transform:translateY(7.5em) !important;
}
.in-page-menu li:nth-child(3).selected ~ li:last-child::after {
transform:translateY(7.5em);
}
.in-page-menu li:nth-child(4):hover ~ li:last-child::after {
transform:translateY(10.5em) !important;
}
.in-page-menu li:nth-child(4).selected ~ li:last-child::after {
transform:translateY(10.5em);
}
.in-page-menu li:nth-child(5):hover ~ li:last-child::after {
transform:translateY(237px) !important;
}
.in-page-menu li:nth-child(5).selected ~ li:last-child::after {
transform:translateY(237px);
}
.in-page-menu--vertical a{
margin-left: -1px;
border-left: 2px solid #eae8e7;
padding: 0.625em 0 1.625em 1.0625em;
}
.in-page-menu a{
font-family: 'montserratlight', sans-serif;
font-weight: 400;
-webkit-font-smoothing: antialiased;
color: #767676;
font-size: 14px;
display: block;
transition: all 150ms;
}
.in-page-menu-vertical a{
margin-left: -1px;
border-left: 3px solid transparent;
padding: 0.625em 0 0.625em 1.0625em;
}
.in-page-menu a{
-webkit-font-smoothing: antialiased;
display: block;
-webkit-transition: all 150ms;
transition: all 150ms;
}
<ul class="in-page-menu in-page-menu--vertical" id="sticky">
<li onclick="selectNav(this)">
<a class="sticky-menu-link" href="#change-content">Change your content web easily</a>
</li>
<li onclick="selectNav(this)">
<a class="sticky-menu-link" href="#manage-order">Manage your order</a>
</li>
<li onclick="selectNav(this)">
<a class="sticky-menu-link" href="#inventory">Inventory management</a>
</li>
<li onclick="selectNav(this)">
<a class="sticky-menu-link" href="#manage-relationship">Manage your relationship</a>
</li>
<li onclick="selectNav(this)">
<a class="sticky-menu-link" href="#bcommerce">B2B commerce</a>
</li>
<li></li>
</ul>
So, I would like it to look like this: SHOPIFY
I’ve also made the demo on jsfiddle. Thank you so much!
Your help will be appreciated 🙂
3
Answers
There were multiple issues with your code. Here they are and the solution to them:
em
withpx
. That is never a good idea. Fixes:.in-page-menu li
items, I made sure that their height is consistent by addingbox-sizing: border-box
, this will include any padding and border into the height calculation, otherwise it won’t.px
sizes withem
, and made an educated guess about the positions. It might not be accurate, but it looks good for these items.~ li:last-child
part from theselected
class selector. This makes sure, that the selected menu item will always have a vertical line.addClass
function to add theselected
class.removeClass
line to find a matchNotes
translateY
positions as well.Working demo
Your CSS is quite complicated for what you’re trying to achieve.
This isn’t exactly the same as the Shopify site, but might help you. There’s a lot going on. Let me know if you’ve any questions, or if I’ve misunderstood you…
jsfiddle
As posted by beerwin. I made some changes too to achieve the result
px
withem
li
li.selected::after
Here is the updated JSFIDDLE