Jump to content

CSS Selectors -- Class names and IDs

Go to solution Solved by tuanphan,

Recommended Posts

Posted

So, I'm trying to make very specific changes to some CSS styles. I figure I'll probably have to use these long class names and IDs as selectors, right? For example, this is just part of one selector:  #yui_3_17_2_1_17011......... > div.fe-block.fe-block-51ced305e6f..... 

However, I'm on a chat with a Squarespace agent right now who told me "So it looks like the ID numbers of the block will change dynamically in version 7.1 sites, so any code targeting a specific ID may not work when the site is refreshed or reloaded."

That's clearly an issue for custom css, no? Again I'm not trying to change every .button or every p, I'm trying to access very specific buttons and text divs, and I feel like I need those IDs and class names to stay the same!

TIA

  • Solution
Posted

Block has 2 type of ID

  • #yui-.. it will change if you reload the page
  • #block-yui_ or #block-... it is static id, you should use this ID

To find Block ID, you can use this free tool https://chrome.google.com/webstore/detail/squarespace-id-finder/igjamfnifnkmecjidfbdipieoaeghcff

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!)

Posted
16 hours ago, SaranyaDesigns said:

@tuanphan oy that makes it very cumbersome... annoying that they won't just generate static IDs for all the blocks, that would make targeting for CSS MUCH cleaner overall. Silly choice by Squarespace!

You can also use JS code to attach a class name to it 😆

Use ideal here

 

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!)

  • 4 months later...
Posted

Hi @tuanphan, I'm in the same boat and trying to create a new class to target a set of specific buttons without having to manually update each block individually. Assume I need to use JS to attach a class name to them? Can you give me any pointers on how I'd go about creating a ".custom-price-button" class so I could simply target this custom class? Thank you!

Also, I've been trying like hell to get the hover state to change the text to blue on hover and can't seem to override the existing style. I've tried !important and targeting the block ID and no dice. Cleared cache. Any pointers?

My current best attempt looks something like this:


#block-yui_3_17_2_1_1712158021426_22128 .sqs-block-button-element--small:hover a {
    color: blue !important; 
}
 

Posted
On 4/4/2024 at 12:21 AM, JA_ATL said:

Hi @tuanphan, I'm in the same boat and trying to create a new class to target a set of specific buttons without having to manually update each block individually. Assume I need to use JS to attach a class name to them? Can you give me any pointers on how I'd go about creating a ".custom-price-button" class so I could simply target this custom class? Thank you!

Also, I've been trying like hell to get the hover state to change the text to blue on hover and can't seem to override the existing style. I've tried !important and targeting the block ID and no dice. Cleared cache. Any pointers?

My current best attempt looks something like this:


#block-yui_3_17_2_1_1712158021426_22128 .sqs-block-button-element--small:hover a {
    color: blue !important; 
}
 

Can you share link to page where you use text/button? We can check easier

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!)

  • 1 month later...
Posted
On 4/3/2024 at 10:21 AM, JA_ATL said:

trying to create a new class to target a set of specific buttons without having to manually update each block individually. Assume I need to use JS to attach a class name to them? Can you give me any pointers on how I'd go about creating a ".custom-price-button" class so I could simply target this custom class? Thank you!

Did you ever figure out how to do this?

  • 5 months later...
Posted

Still looking for a solution here to apply a class name versus relying on #block ID.

I have a lot of modified CTA buttons but also other sections of my website that I target with CSS to make changes from the standard text styling. I don't want to broadly change all squarespace selectors, but I also don't like that my only other option appears to be using a #block ID to to select what I modify in CSS. The issue with using Block ID is whenever I duplicate a page, I have to go back in and change all the old block IDs to the new ones.

 

It would be so much easier if I could assign a section a class name like "faq.Section" instead of using section[data-section-id="67017fdc67a26006207dd834"], which requires me to manually update if I clone my page. Then if I clone the page, the CSS in the advance section would still be faq.Section, and wouldn't require styling adjustments for old IDs.

Has anyone solved a custom code option for giving an entire section a class name?

Posted
10 hours ago, Giving_Machine said:

Still looking for a solution here to apply a class name versus relying on #block ID.

I have a lot of modified CTA buttons but also other sections of my website that I target with CSS to make changes from the standard text styling. I don't want to broadly change all squarespace selectors, but I also don't like that my only other option appears to be using a #block ID to to select what I modify in CSS. The issue with using Block ID is whenever I duplicate a page, I have to go back in and change all the old block IDs to the new ones.

 

It would be so much easier if I could assign a section a class name like "faq.Section" instead of using section[data-section-id="67017fdc67a26006207dd834"], which requires me to manually update if I clone my page. Then if I clone the page, the CSS in the advance section would still be faq.Section, and wouldn't require styling adjustments for old IDs.

Has anyone solved a custom code option for giving an entire section a class name?

With button, if you don't want to target ID, you can target href

For example your button has url: https://google.com, you can target selector like this

div.button-block:has(a[href="https://google.com"]) {
CSS value
}

With this way, when you duplicate the page, the code will work with duplicated button

Do similar with section

section.page-section:has(a[href="https://google.com"]) {
CSS value
}

 

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!)

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.