- This topic has 20 replies, 2 voices, and was last updated 4 years, 11 months ago by
Leo.
-
AuthorPosts
-
August 15, 2015 at 9:02 am #129543
Herschel
Hi all,
I would like to add a separator like “|” between menu items on my menu/navigation bar.
Can anyone tell me what CSS code to use for this as well as how to do it in different colors?
Thanks.
August 15, 2015 at 10:28 am #129569Tom
Lead DeveloperLead DeveloperHi there,
Give this a shot:
.main-navigation .menu > li > a { border-right: 1px solid #000000; } .main-navigation .menu > li:last-child > a { border-right: 0; }August 15, 2015 at 11:23 am #129581Herschel
Thanks Tom, but it still will not show up.
I’m working offline in Xampp.
I’m used the Simple Custom CSS Plugin for this.Should I add the code in somewhere else or what could be the problem?
August 15, 2015 at 11:43 am #129583Herschel
Not to worry, I figured it.
It works now – I added the code to style.css.
Thanks.
August 15, 2015 at 11:44 am #129584Tom
Lead DeveloperLead DeveloperAwesome 🙂
February 9, 2017 at 10:08 am #276642Nick
Hey Tom,
This worked like a charm! Is there a way to make the border not be the whole height of the main navigation? Like if I wanted it to be like
Menu Item | Menu Item 2 | Menu Item 3
With the “separator” not being so tall?
Thanks!
February 9, 2017 at 12:48 pm #276701Tom
Lead DeveloperLead DeveloperHmm using the border attribute will always go full height of the element.
You could get fancy though..
@media (min-width: 769px) { .main-navigation .main-nav > ul > li:not(:last-child) { position: relative; } .main-navigation .main-nav > ul > li:not(:last-child) > a:after { content: ""; height: 20px; width: 1px; background: red; display: block; position: absolute; right: 0; top: 50%; margin-top: -10px; /* half of your height */ } }February 9, 2017 at 1:00 pm #276716Nick
Hey Tom,
This is why I’m such a fan of GeneratePress (and you). You go the extra mile to solve people’s problems. I’d done something similar in the past but not nearly as elegant since my CSS chops are average.
Your solution works like a charm 🙂
Thanks again for the stellar support.
February 9, 2017 at 1:00 pm #276719Tom
Lead DeveloperLead DeveloperAwesome, glad I could help! 🙂
April 24, 2017 at 10:01 am #309690Heidi
Just saying, best theme ever! I am building a restaurant site with separators in the Menu/Nav (thanks for the help there), but I also have a Centered Logo in the Nav and wanted to remove the separators before and after the Logo when full width, but keep them when it’s smaller than 1022px width. You can see the site in progress here: http://eathax.com
Full width screenshot:
http://eathax.com/wp-content/uploads/2017/04/Screen-Shot-2017-04-24-at-9.47.53-AM.png1022px screenshot:
http://eathax.com/wp-content/uploads/2017/04/Screen-Shot-2017-04-24-at-9.47.36-AM.pngSo, my question is, how do I modify specific separators?
Thanks for your advice as always.
April 24, 2017 at 6:49 pm #309849Tom
Lead DeveloperLead DeveloperHi Heidi,
First, you would use this selector instead of the one you’re using:
.main-navigation .main-nav > ul > li:not(:last-child):not(.centered-navigation-logo) > a:afterThen for the item before the logo, give it a class like this:
ignore-borderThen do this:
@media (min-width: 1023px) { .main-navigation .main-nav > ul > li.ignore-border > a:after { display: none; } }April 24, 2017 at 8:32 pm #309876Heidi
Ah ha! I get it now. Thanks so much for your speedy reply– as always! I tweaked the code a little to make it work:
.main-navigation .main-nav > ul > li:not(:last-child):not(.centered-navigation-logo):not(.ignore-border) > a:after { content: "|"; display: block; position: absolute; right: 0; top: 0; font-size: 20px; color: #ac4c20; } @media (max-width: 1023px) { .main-navigation .main-nav > ul > li.ignore-border > a:after { content: "|"; display: block; position: absolute; right: 0; top: 0; font-size: 20px; color: #ac4c20; } }April 24, 2017 at 9:22 pm #309889Tom
Lead DeveloperLead DeveloperPerfect, thanks for sharing your code 🙂
June 10, 2017 at 3:30 pm #331736Matthew
Thank you for your excellent theme.
I used the code you recommended above (your first recommendation) and it worked great for the horizontal menu navigation bar at the top of the page. As a side note the code did not work when I used the Simple CSS plugin but it worked great when I used WP’s built in additional CSS functionality.
However, what I was wondering was how do I add separators to the menus that are vertical as part of the side bars?
My regards,
Matthew
June 10, 2017 at 3:40 pm #331739Leo
StaffCustomer SupportHi there,
If the code worked in Addtional CSS and not Simple CSS then it’s likely that there is a syntax error in the Simple CSS editor already which stops the code from executing.
You can check here: https://jigsaw.w3.org/css-validator/#validate_by_input
Can you provide a link to your site with the side bar menus? I thought each menu item should has its own row so doesn’t need to be separated?
-
AuthorPosts
- The topic ‘Separators in Menu/Nav Bar’ is closed to new replies.