Jump to content

How do I target a specific link in the main menu with CSS?

Go to solution Solved by tuanphan,

Recommended Posts

  • designbyjrs changed the title to How do I target a specific link in the main menu with CSS?
  • Solution

Add to Design > CUstom CSS

nav.header-nav-list>div:nth-child(1) a, .header-menu-nav-folder[data-folder="root"]>div>div:nth-child(1) a {
    color: #f1f !important;
}
nav.header-nav-list>div:nth-child(2) a .header-menu-nav-folder[data-folder="root"]>div>div:nth-child(2) a {
    color: red !important;
}
nav.header-nav-list>div:nth-child(3) a, .header-menu-nav-folder[data-folder="root"]>div>div:nth-child(3) a {
    color: green !important;
}
nav.header-nav-list>div:nth-child(4) a, .header-menu-nav-folder[data-folder="root"]>div>div:nth-child(4) a {
    color: brown !important;
}

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • 4 months later...
On 8/15/2023 at 3:10 AM, giorgiasage said:

hi @tuanphan, this solution worked great for creating faux-button styles for some of my links.

However, I want to target their outer container to use a flex-grow property to force a line break in the nav link flexbox. Is there a way to modify this code to do so?image.thumb.png.acc4d8e1c12bab7259b27c36f9267509.png

Which position you want to add line break? after Apply item or?

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • 6 months later...
On 3/5/2024 at 3:12 AM, hey_sp said:

Hi @tuanphan I think this is a similar issue. I have two buttons in my main nav and I want to just target one of them. Is there a way for me to change the background colour of just the "Match with a Therapist" button in my header nav?

https://goldfish-wrasse-48kn.squarespace.com/
password: igc

You can use this CSS code

#siteWrapper header#header a.btn:nth-child(2) {
    background-color: #f1f !important;
}

Note: this code will target both Button Header in Desktop + Mobile

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • 3 months later...

Hi Everyone,

Is there a way to use the same type of child logic to to apply the below code the each individual folder nav title? I want each section to have a different coloured underline on active (folder title only not content), If I was able to achieve it on hover as well then even better...

Currently I have this which does it on all folder titles:

.header-nav-item--active a {
  background-image: none !important;
  border-bottom: 5px solid #20AECF;
  }

.header-nav-folder-content a{
  border-bottom: none;
}

Link to comment
On 6/24/2024 at 3:51 PM, rfung said:

Hi Everyone,

Is there a way to use the same type of child logic to to apply the below code the each individual folder nav title? I want each section to have a different coloured underline on active (folder title only not content), If I was able to achieve it on hover as well then even better...

Currently I have this which does it on all folder titles:

.header-nav-item--active a {
  background-image: none !important;
  border-bottom: 5px solid #20AECF;
  }

.header-nav-folder-content a{
  border-bottom: none;
}

Use something like this

div.header-nav-item:nth-child(3)>a {
     background-image: none !important;
  border-bottom: 5px solid #20AECF !important;
}

image.png.e08a178e418c10418b5cad87ad596adc.png

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Brilliant, this works to have them with an underline permanently. Is there a way to make it only happen on hover and when 'active'?

 

div.header-nav-item:nth-child(1)>a {
     background-image: none !important;
  border-bottom: 5px solid #e94562 !important;
}


div.header-nav-item:nth-child(2)>a {
     background-image: none !important;
  border-bottom: 5px solid #20aecf !important;
}


div.header-nav-item:nth-child(3)>a {
     background-image: none !important;
  border-bottom: 5px solid #fab92c !important;
}

div.header-nav-item:nth-child(4)>a {
     background-image: none !important;
  border-bottom: 5px solid #c9d53c !important;
}

Link to comment

Ah I've got it: 

div.header-nav-item:nth-child(1)>a:hover {
     background-image: none !important;
  border-bottom: 5px solid #e94562 !important;
}

Thank for all your help 🙂

 

Link to comment

@tuanphan

Sorry, I have changed how I'm achieving the line as it was moving the nav up and down before. Instead I have worked out how to grab and tweak SS standard active underline and tweak it. However I can't work out how to apply child logic to nav links 1 - 4 now, as the code setup is different... any ideas? The below shows how I am currently applying one colour to folder titles both in hover and active state. I would like to change the " background-image: linear-gradient(#e94562, #e94562);"  for the 4 nav titles:

 

//GRAB SS active underline:

body:not(.header--menu-open) .header-nav-item--active>a {
    background-image: linear-gradient(#e94562, #e94562);
    background-repeat: repeat-x;
    background-size: 1px 3px;
    background-position: 0 100%;
    background-position: 0 calc(100% - 0.1em);
}

//Apply SS underline style on hover:

body:not(.header--menu-open) .header-nav-item>a:hover {
    background-image: linear-gradient(#e94562, #e94562);
    background-repeat: repeat-x;
    background-size: 1px 3px;
    background-position: 0 100%;
    background-position: 0 calc(100% - 0.1em);
}

 

Any ideas?

 

Link to comment

Ah this seems to have solved it:


//hover
div.header-nav-item:hover:nth-child(1)>a {
     background-image: linear-gradient(#e94562, #e94562);
    background-repeat: repeat-x;
    background-size: 1px 3px;
    background-position: 0 100%;
    background-position: 0 calc(100% - 0.1em);
}
//active
div.header-nav-item--active:nth-child(1)>a {
     background-image: linear-gradient(#e94562, #e94562);
    background-repeat: repeat-x;
    background-size: 1px 3px;
    background-position: 0 100%;
    background-position: 0 calc(100% - 0.1em);
}

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.