- This topic has 13 replies, 3 voices, and was last updated 4 years, 1 month ago by David.
-
AuthorPosts
-
February 26, 2020 at 6:23 am #1177368Andy
Hi,
I’m trying to make each menu list item the same width but also break longer anchor tags on to 2 lines. I’ve added a line break to the longer item but can’t get it to align centrally and fill the height of the list item.
Any help appreciated.
February 27, 2020 at 12:02 am #1178250TomLead DeveloperLead DeveloperHi there,
I wonder if this would do it:
.main-navigation:not(.toggled) .main-nav ul li a { line-height: normal; } .main-navigation:not(.toggled) .main-nav ul li { height: 65px; display: flex; align-items: center; }
Let me know 🙂
February 27, 2020 at 4:27 am #1178456AndyThanks Tom, thats made the menu items equally spaced and centred the text. However now the anchor tag doesn’t fill the height of the li tag.
Any further assistance appreciated.
February 27, 2020 at 9:27 am #1178919DavidStaffCustomer SupportHi there,
try this CSS instead:
.main-navigation:not(.toggled) .main-nav ul li { height: 65px; display: flex; flex-direction: column; } .main-navigation:not(.toggled) .main-nav ul li a { line-height: normal; flex: 1; display: flex; align-items: center; }
February 27, 2020 at 9:50 am #1178934AndyThank you, that corrects the height issue but now the li’s are not equal widths. Also is there any way for the widths to reduce until the toggle menu kicks in?.
February 27, 2020 at 10:01 am #1178941DavidStaffCustomer SupportCan you disable your cache ? Make it easier to tweak the CSS in dev tools.
With equal widths – is this to divide up the total space available or a minimum pixel width ?
March 5, 2020 at 5:23 am #1185715AndySorry David, I thought I’d replied to this but I must have not pressed submit.
Ideally, it would be a minimum pixel width of say 210px. Also, when I change my navigation settings to ‘Use navigation as header’ it breaks the layout making the navigation display as a vertical list squashed into the right-hand corner. So for the time being I’ve had to comment out that code. But by doing so it breaks the 2 line alignment.
Any further help appreciated.
March 5, 2020 at 7:14 am #1186001DavidStaffCustomer SupportYeah the Navigation as Header and the floated nav uses different CSS.
So how will this underline hover effect work if we vertically center the nav elements – as the baseline for your 2 line menu item will be lower ?March 5, 2020 at 7:24 am #1186018AndyI will just move the underline hover effect to below the 2nd line, the same distance apart as the other links.
March 5, 2020 at 8:09 am #1186069DavidStaffCustomer SupportTry this CSS to vertically center links whilst maintaining the full height hover:
.main-navigation ul { display: flex; align-items: center; flex: 1; } .main-navigation .main-nav ul li a { line-height: 40px; padding-top: 20px; padding-bottom: 20px; text-align: center; }
March 5, 2020 at 8:15 am #1186083AndyThank you works perfectly. Not sure having the equal width li items is totally necessary but would be good if possible.
March 5, 2020 at 8:43 am #1186103DavidStaffCustomer SupportSo try this CSS instead:
@media (min-width: 1000px) { .main-navigation ul { display: flex; align-items: center; justify-content: flex-end; flex: 1; } .main-navigation .main-nav ul li a { line-height: 40px; padding-top: 20px; padding-bottom: 20px; text-align: center; } .main-navigation:not(.slideout-navigation) .main-nav { flex: 1; } .main-navigation li { flex: 1 0 20%; max-width: 240px; /* Adjust accordingly or remove */ } }
I would suggest reducing the Customizer > Layout > Primary Nav > Menu Item Width to around 20px.
March 5, 2020 at 5:24 pm #1186508AndyThank you David, awesome code as always!. I’m pretty comfortable with CSS but still find the flexbox layout a little difficult to implement with more complex designs.
Thanks again!
March 6, 2020 at 5:25 am #1186858DavidStaffCustomer Supportyeah Flex can be a bit of a mind bender _ glad to be of help.
-
AuthorPosts
- You must be logged in to reply to this topic.