Tip: Collapsible headers in articles or templates (accordions)

90 Comments

  • 小林正左子

    Hello, team.

    What a great tip you've provided, I'm so impressed!
    我试过只要我能,但我不能view the sentences that are collapsed in sections.
    I set it up as you wrote, but I wonder if there is something I am missing.

    I hope you will be able to solve the problem.

    Thank you.

    0
  • Trapta Singh
    Community Moderator

    Can you check if you are getting any errors in your console? If possible please share the URL of your HC so we can take a look at it.

    谢谢

    0
  • 小林正左子

    Hi Trapta,

    For security reasons, it's not safe to post the URL, so can I send you an email directly?

    By the way, the error message was not displayed in script.js, style.css, or HTML code.

    谢谢

    0
  • Trapta Singh
    Community Moderator

    @Kobayashi, sure you can. Please find the email ID in my profile.

    谢谢

    0
  • Montana Steele

    Ifra Saqlain, amazing tip! I've just implemented this on my help center for a step-by-step process and it's gorgeous. One question - do you happen to know how i could turn an accordion step into an anchored link that automatically opens to the right step? i.e. we want to send some of our users directly to the correct step in the process, and have it auto-open where we send them once they've clicked the link. do you know if this is possible with this accordion set-up?

    2
  • Elizabeth Barron

    This is great, thanksIfra Saqlain!
    How would we make one auto-close when the next is clicked?

    0
  • Tony Jansson

    Hi,

    Do anyone have any example pages where I can test this functionality where it has been implemented? :)

    谢谢in advance!

    0
  • Trapta Singh
    Community Moderator

    Hi @Tony Jansson,

    I have updated the post to add a demo link for the same as well as to add the bottom margin to accordions in case of more than one.

    谢谢

    2
  • Julio Cesar

    Awesome jobTrapta Singh, just implemented it in a critical article that we have here, thank you so much for sharing.

    1
  • Tony Jansson

    谢谢for uploading a demoTrapta Singh:)

    Hope it is okey with a follow-up question:

    As i understand, the demo shows articles that collapses with headers, Is this also something that is possible to apply to sections?

    Example if i click on a section header that expands with article titles, and then again expand the article when clicking on the title? (like everything shows up on same page).


    0
  • Trapta Singh
    Community Moderator

    HiTony Jansson,

    Yes, it is possible. In order to achieve what you want, you need to tweak code a little bit to make it work accordingly.

    谢谢

    0
  • Lisa Sedlak

    谁有答案Montana Steele's question?

    I have accordions and they look awesome. But I would like to link to specific ones in other articles.

    In addition, is there a way to make accordions searchable? As in when they search on the site or do CTRL-F they can find the right accordion?

    谢谢!

    0
  • Eduardo Escobar

    Hello, is there a way to make an accordion within a accordion? As in one section that has more sub sections?

    0
  • Dave Dyson
    Hi Eduardo,

    I found this method combining HTML and CSS. Note that you will have to enable unsafe content in your help center in order for this method to work (seeAllowing unsafe HTML in help center articles ). It's possible that there may be other methods that don't require enabling unsafe content, though:https://www.cssscript.com/multilevel-accordion-menu-with-plain-html-css/
    0
  • Realis Support

    Hello there,

    如何使折叠在一个地方吗?我不t want to have space between them, not sure how to do that.Any idea how to make it like in the "line" example? My code is


    Testing:
    Test



    Section 1





    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.




    Section 2





    Web check this out!.




    Section 3





    Web check this out!.


    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Hey RasmonT,

    Solution 1:

    Go to your stylesheet > Pressctrl + f> Find.accordionclass > Removemargin-bottom: 10px

    Screenshot for the same:

    Solution 2:

    Go to your stylesheet > Paste the given code at the bottom onstyle.cssfile.

    .accordion {
    margin-bottom:0
    }

    Screenshot for the same:

    谢谢

    1
  • Eduardo Escobar

    Hello is there a way to change the 'Plus' and 'Minus" symbols to be something else? Or change the color of the symbol when the mouse is hovered over it? Thanks

    0
  • Pulkit Pandey
    Community Moderator

    HiEduardo Escobar

    You can update thecontentvalue according to your choice offont icon

    Here are the below code where I have updated the 'Plus' and 'Minus" symbols to the Chevron icon, you can place the below code at the bottom of your style.css file

    .accordion:after {
    content: '\f078';
    }

    .active:after {
    content: "\f077";
    }

    Let me know if need any further assistance on that

    Thank You

    Pulkit

    TeamDiziana

    0
  • Eduardo Escobar

    Thank youPulkit Pandey, one last question. How do I change the color of the icon when I hover over the accordion? Like from gray to white. Thanks!

    0
  • Michael Bui

    is there code to collapse all or expand all?

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    @Michael Bui, yes, you can pick the above points to get it done.

    1). Create an article as given the HTML structure.

    2). Add CSS to your stylesheet - given above in this tip.

    3). Add JS code your script.js file - given above in this tip.

    4). You have done now, your all accordion items will be expanded when you click.

    OR

    You can explain more about your query.

    谢谢

    0
  • Michael Bui

    Ifra Saqlain

    I was more thinking of expand all if I have let's say 10 accordion on the page. I was looking for the ability to expand them all or collapse them all via a click/button/link.

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    HeyMichael Bui,

    Use the below script code to expand all accordion in one click.

    $(document).ready(function(){
    $(".panel").slideUp();
    $(".accordion").click(function (){
    $(".accordion").toggleClass("active");
    $(".panel").slideToggle();
    });
    });

    And remove max-height from the 'panel' class in the CSS code.

    谢谢

    Team

    0
  • Michael Bui

    Ifra Saqlainsorry to keep bothering you, I implemented the code. If I click on an an accordion, it tries to expand all but I see one or multiple that doesn't expand

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Remove your previous added script code which you have been using and add the script code at the end of script.js file which I have shared with you, and then find for '.panel' in your CSS code and remove '.max-height'.

    Now you face any issue, share your public Help Centre URL here, so I can figure it out.

    谢谢

    Ifra

    0
  • Eduardo Escobar

    Hello, I'm wondering how can add some space between the panel and next accordion box. As shown, they are connected and would like a small space between them. Thanks

    0
  • Tipene Hughes
    Zendesk Developer Advocacy

    HiEduardo Escobar!

    You can add space between the panel and accordion box by adding margin to the .panel selector in the styles.css file. Here's an example of how that could look:

    .panel {
    padding: 0 18px;
    margin: 5px;
    background-color: white;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease-out;
    }

    I hope this helps! Feel free to reach out with any questions.

    Tipene

    0
  • Salim Moumouni

    Do we have an answer on the below?

    "do you happen to know how i could turn an accordion step into an anchored link that automatically opens to the right step? i.e. we want to send some of our users directly to the correct step in the process, and have it auto-open where we send them once they've clicked the link. do you know if this is possible with this accordion set-up? "

    2
  • Salim Moumouni

    Also how can I update the colour of the sections to not be white since its blending in with the background?

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Hey Salim

    Do you want an open accordion not closed?

    0

Pleasesign into leave a comment.

Powered by Zendesk