Jump to content

[Share] Accordion Block: Useful code

Go to solution Solved by Parker_SQSP,

Recommended Posts

10 hours ago, marcoadrielmunoz said:

#9. Accordion Titles – Add Line Break

I have three seperate accordions on my one page site. The code seems to only work for the first accordion. How might I add this functionality to my other accordions? Thanks!

- Marco

Website: https://antelope-harpsichord-4wpr.squarespace.com

You can try this approach

First, edit accordion title to this

Accordion Item 1  <br/>Red text

Next, add this code into Page Header (Page where you added accordion

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("span.accordion-item__title").each(function(){
    $(this).html($(this).text());
  });
});
</script>

 

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 hours ago, clare1 said:

@tuanphanhi, im adding an image to the accordion but it now shows in ALL my accordions  - can I add it multiple times but to different accordions throughout my site? How do I specify which one? Thanks! 

Can you share link to page where you use accordion + which code did you use?

--

Also, I sent you an email on this.

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
31 minutes ago, thewayfaringdesigner said:

Hi @tuanphan! This is fantastic info. Wondering if you can help me target a single accordion block to remove the expand icons? I have multiple accordions on the same page, and to keep the look consistent I want to use it for a section list that doesn't require any drop downs. Thanks!

In case anyone is looking for this solution I used this CSS: 

section[data-section-id="insert-section-id-here"] .sqs-block-accordion .accordion-icon-container>* {
    display: none;
}

Link to comment
1 hour ago, thewayfaringdesigner said:

In case anyone is looking for this solution I used this CSS: 

section[data-section-id="insert-section-id-here"] .sqs-block-accordion .accordion-icon-container>* {
    display: none;
}

If you have 2 or more accordions on same section, you can target block id.

#accordion-block-id .accordion-icon-container>* {
    display: none;
}

 

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
On 5/19/2022 at 1:40 PM, JTeich said:

Thank you so so much!

Silly question, but how do i make all four corner rounded. The code says 

border-bottom-right-radius: 10px;
    border-bottom-left-radius: 10px;

but that obviously isn't it

 

Thanks again!

Replace the paragraph with this:

/* make last item round corner */
li.accordion-item:last-child .accordion-item__title-wrapper {
    border-bottom-right-radius: 10px;
    border-bottom-left-radius: 10px;

Link to comment
  • 3 weeks later...
  • Solution

Hi all!

Great tips and insights, @tuanphan! I also wanted to pop in to share that a background color can be added to Accordion blocks (as well as some other blocks) directly in Squarespace for any folks who may be looking to do that. 

Here's some more on that: 

https://support.squarespace.com/hc/en-us/articles/205815278#toc-change-block-background-colors

Link to comment
On 8/9/2022 at 12:14 AM, DevonHarris said:

hey guys!

My accordion looks great on desktop, but I was hoping to write some code that would change the location of the + icon (here I have replaced the + with an image) to the TOP of the section on mobile.  Any ideas?  See desktop below:

 

image.thumb.png.739786752a2845519680a647310ee8a6.png

What is page url? 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!)

Link to comment
10 hours ago, DevonHarris said:

www.tlastmarks.com/health 🙂. thanks!  I have currently just used an image block, and then accordion, 3 times.  But the spacing is off and I'd rather just use the single block if possible...

What is access password?

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
On 8/11/2022 at 7:20 PM, DevonHarris said:

access PW is: Devon   thanks!

Add to Design > Custom CSS

@media screen and (max-width:767px) {
.fe-block-yui_3_17_2_1_1660051489419_107975 {
    grid-column-start: 2;
}
.fe-block-yui_3_17_2_1_1660051489419_107975 * {
   text-align: left !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
On 8/19/2022 at 3:18 AM, crisisandcreativity said:
@tuanphan

Hi! With regard to the below, is there a way to do this to only one page and not across all accordions?
Also, how to shorten the length between where the text ends and where the dividers end / icon (on the right) is?

Thank you!

@media screen and (min-width:768px) {
.accordion-item__description  {
   columns: 2;
 column-gap: 30px;
    }
}

#1. Add a Code Block under Accordion > Use this code

<style>
  @media screen and (min-width:768px) {
.accordion-item__description  {
   columns: 2;
 column-gap: 30px;
    }
}
</style>

#2. Can you share link to page where you use accordion?

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
On 8/26/2022 at 12:01 PM, SophieCartwright said:

Hi @tuanphan

I have use the code from #14 to add an image to the top of my accordion block. 

But the full image isn't show on mobile. 

How can I fix this?

Screen Shot 2022-08-26 at 3.01.06 pm.png

Screen Shot 2022-08-26 at 3.01.15 pm.png

Add this code under for mobile

@media screen and (max-width:767px) {
li:nth-child(1) .accordion-item__description:before {
    height: 100px; /* image height */
}
}

You can adjust 100px

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
  • 2 weeks later...

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.