Jump to content

Adding dropdown/accordion with images inside

Go to solution Solved by jamesmabrown,

Recommended Posts

Hello,

I'm trying to add an accordion/dropdown to a website (it's still in trial at the moment so can't share web link). It is going to be used on a page showing the team of a company, so within each entry it also needs to include a picture of them.

I have used the standard markdown used for an accordion, which by itself (without an image in it) works fine. I have then used an HTML image reference within it, and when it does this, only the first name appears. And when it is opened/clicked, the next name then appears below it (and so forth). But then when you close the top name, they all disappear (apart from the top one).

I have also tried created an animated collapsible using HTML, CSS and Java (https://www.w3schools.com/howto/howto_js_collapsible.asp). This code was copied exactly, using a code block for the HTML, adding the CSS into the custom CSS, and adding the Javascript into the page specific code injection. The list options are created, but don't actually open when clicked on. 

If anyone can provide any insight into how to get either of these solutions to work that would be greatly appreciated. Screenshots are attached for reference.

To confirm, I'm using the Henson template.

Many thanks,

James

Screenshot 2021-01-08 at 11.49.33.png

Screenshot 2021-01-08 at 11.49.39.png

Screenshot 2021-01-08 at 11.50.04.png

Screenshot 2021-01-08 at 11.50.08.png

Screenshot 2021-01-08 at 11.50.58.png

Screenshot 2021-01-08 at 11.51.11.png

Screenshot 2021-01-08 at 11.52.16.png

Link to comment

Hi. If you can share site url, we can check easier.

If your site is private/trial, you can setup password & share url.

If you can't share url, you can consider using this Accordion Plugin. It has more options & easy to install.

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

Hi @tuanphan,

There is a link to the site here: https://nectarine-tuba-pgnf.squarespace.com/contact-us-3
PW: PeoplePlacePurpose

I have managed to find a solution to it, using HTML and CSS, but have now run in to the issue that it does not scale properly for mobile (i.e. the content cuts off and cannot be scrolled), and I also can't align the IMG within the content without it affecting the rest of the dropdown. Ideally I'd have the image fixed left (or right) with the text flowing next to it. As a reference, I want to try and get this (https://nectarine-tuba-pgnf.squarespace.com/contact-us-5-grid-2) but collapsible. 

If you can provide any advice it would be greatly appreciated.

All best,

James

Edited by jamesmabrown
providing reference
Link to comment
20 hours ago, jamesmabrown said:

Hi @tuanphan,

There is a link to the site here: https://nectarine-tuba-pgnf.squarespace.com/contact-us-3
PW: PeoplePlacePurpose

I have managed to find a solution to it, using HTML and CSS, but have now run in to the issue that it does not scale properly for mobile (i.e. the content cuts off and cannot be scrolled), and I also can't align the IMG within the content without it affecting the rest of the dropdown. Ideally I'd have the image fixed left (or right) with the text flowing next to it. As a reference, I want to try and get this (https://nectarine-tuba-pgnf.squarespace.com/contact-us-5-grid-2) but collapsible. 

If you can provide any advice it would be greatly appreciated.

All best,

James

Hi,

Which code did you use? Can you post here? We will try tweaking it.

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

Hi @tuanphan,

The HTML is here:

<div class="row">
  <div class="col">
    <h1>OUR TEAM</b></h1>
    <div class="tabs">
      <div class="tab">
        <input type="checkbox" id="chck1">
        <label class="tab-label" for="chck1">
			<h2>Thomas Rose, Co-Founder
			</h2>
		</label>
        <div class="tab-content">
			           <img src="https://i.ibb.co/ZXt6CVT/Screenshot-2021-01-07-at-17-14-58.png" align=”left” style=”margin: 0px 10px 0px 0px;” width="300px">
          Thomas Co-founded P-THREE in 2019 after working as head of Leisure & Restaurants at Cushman & Wakefield for 13 years.<br>

Thomas has worked on projects across the UK and Europe including Battersea Power Station, Waterloo.London, Savarin Prague, Potsdamer Platz Berlin, Trocadero Estate, Wembley Park and Kensington Olympia. Thomas has advised private equity groups on over £1billion of acquisitions and retained mandates for Third Space, Wahaca, Rosa’s Thai, Chipotle and Puttshack.<br>

Thomas is a member of RICS and a Committee Member of the Leisure Property Forum.
          




        </div>
      </div>
      <div class="tab">
        <input type="checkbox" id="chck2">
        <label class="tab-label" for="chck2"><h2>
          
          Justin Taylor, Co-Founder</h2></label>
        <div class="tab-content">
          Lorem ipsum dolor sit amet consectetur adipisicing elit. A, in!
        </div>
      </div>
    </div>
  </div>

and the CSS is here:

// General

input {
  position: ;
  opacity: 0;
  z-index: -1;
}
// Layout
.row {
  display:flex;
  .col {
    flex:1;
    &:last-child {
      margin-left: 1em;
    }
  }
}
/* Accordion styles */
.tabs {
  border-radius: 0px;
  overflow: hidden;
}
.tab {
  width: 100%;
  color: ;
  overflow: hidden;
  &-label {
    display: flex;
    justify-content: space-between;
    padding: 1em;
    background: ;
    font-weight: bold;
    border-bottom: 1px solid #f7b8a1; 
  	padding-bottom:20px;
    cursor: pointer;
/* Icon */
    &:hover {
      background: ;
    }
    &::after {
      content: "\276F";
      width: 1em;
      height: 1em;
      text-align: center;
      transition: all .35s;
    }
  }
  &-content {
    max-height: 0;
    padding: 0 0em;
    color: ;
    background: ;
    transition: all .35s;
  }
  &-close {
    display: flex;
    justify-content: flex-end;
    padding: 1em;
    font-size: 0.75em;
    background: ;
    cursor: pointer;
    &:hover {
      background: ;
    }
  }
}

// :checked
input:checked {
  + .tab-label {
    background: ;
    &::after {
      transform: rotate(90deg);
    }
  }
  ~ .tab-content {
    max-height: 100vh;
    padding-top: 10px;
  }
}

Many thanks,
James

Link to comment
  • Solution

Just an update, this has now been resolved. For anyone that wants to do something similar in the future, the full code is here.

HTML here
<div class="row">
  <div class="col">
    <h1>Heading here</b></h1>
    <div class="tabs">
      <div class="tab">
        <input type="checkbox" id="chck1">
        <label class="tab-label" for="chck1">
			<h2>Title here.
			</h2>
		</label>
        <div class="tab-content">
          <div class="container">
            
        
		<img src="URL" class="container__image"> <div class="container__text">
            <p>
Some internal content here.
            </p>

            </div>
  </div>

        </div>
      </div>
      <div class="tab">
        <input type="checkbox" id="chck2">
        <label class="tab-label" for="chck2"><h2>
          
          A title here</h2></label>
        <div class="tab-content">
          <div class="container">
            
        
		<img src="URL" class="container__image"> <div class="container__text">
            <p>
Some internal content here.
            </p>

            </div>
  </div>
        </div>
      </div>
      
      
/*CSS here*/
      
      // General

input {
  position: ;
  opacity: 0;
  z-index: -1;
}
// Layout
.row {
  display:flex;
  .col {
    flex:1;
    &:last-child {
      margin-left: 1em;
    }
  }
}
/* Accordion styles */
.tabs {
  border-radius: 0px;
  overflow: hidden;
}
.tab {
  width: 100%;
  color: ;
  overflow: hidden;
  &-label {
    display: flex;
    padding: 1em;
    background: ;
    justify-content: space-between;
    font-weight: bold;
    border-bottom: 1px solid #f7b8a1; 
  	padding-bottom:20px;
    cursor: pointer;
/* Icon */
    &:hover {
      background: ;
    }
    &::after {
      content: "\276F";
      width: 1em;
      height: 1em;
      text-align: center;
      transition: all .35s;
    }
  }
  &-content {
    max-height: 0;
    padding: 0 0em;
    color: ;
    background: ;
    transition: all .35s;
  }
  &-close {
    display: flex;
    justify-content: flex-end;
    padding: 1em;
    font-size: 0.75em;
    background: ;
    cursor: pointer;
    &:hover {
      background: ;
    }
  }
}

// :checked
input:checked {
  + .tab-label {
    background: ;
    &::after {
      transform: rotate(90deg);
    }
  }
  ~ .tab-content {
    max-height: 150vh;
    padding-top: 10px;
}
  }
      
      .container {
  &__image {
    display: inline-block;
    vertical-align: top;
    width: 25%;
    margin-right: 25px;
    position: relative;
    min-width: 200px;
    margin-bottom: 20px;
  }
  &__text {
    display: inline-block;
    width: 60%;
    font-size: 1.3em;
    overflow: visible;
    @media (max-width: 1000px) {
      width: 100%;
    }
  }
}

 

Link to comment
  • 7 months later...
On 9/4/2021 at 12:30 AM, alejoreinoso said:

Hello, 

I tried this example and it works, but  mobile version go to hell. Is there any extra code to solve this mobile problem? Or the best way is to buy a plugin? Thank you. 

Hi,

What problem on mobile? Can you describe & share link to page where you have problem?

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
  • 1 month later...
On 10/12/2021 at 2:26 AM, alejoreinoso said:

Thank you @tuanphan for the answer. Sorry for the delay but client change his mind so I solved the problem. 
Now I am trying to look for some guide (or maybe someone who can do it for us) to have a section where we can compare some products , best example, something like this: https://www.apple.com/iphone/compare/

Is there a way to do it on Squarespace?

I think this is require a lot of code. You should post this on some FB groups to hire some devs

  • Squarespace Customization Resource Group
  • Squarespace Community

(I don't offer service)

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 months later...

I used this code and it works great. However; I notice in this example the checkbox isn't appearing, but on mine there is a visible checkbox which I would prefer wasn't there. (see attached) When I isolate the "checkbox" input in the code and remove it the accordion no longer opens. Is there a way I can remove or hide the checkbox?

 

Thank you!

Screen Shot 2021-12-15 at 1.09.29 PM.png

Link to comment
On 12/16/2021 at 1:09 AM, laurensmithart said:

I used this code and it works great. However; I notice in this example the checkbox isn't appearing, but on mine there is a visible checkbox which I would prefer wasn't there. (see attached) When I isolate the "checkbox" input in the code and remove it the accordion no longer opens. Is there a way I can remove or hide the checkbox?

 

Thank you!

Screen Shot 2021-12-15 at 1.09.29 PM.png

If you share link to page in screenshot, we can give the code to hide checkbox.

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 weeks later...
On 1/10/2022 at 11:59 PM, laurensmithart said:

One more question... Is there a way to make this two columns? I keep trying to split the code up and place the blocks next to each other but when I view it live it is all one column.

Use this code

/* product recommendations */
@media screen and (min-width:768px) {
.tabs {
    display: grid;
    grid-template-columns: repeat(2,1fr);
}
}

 

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

Use this code

/* product recommendations */
@media screen and (min-width:768px) {
.tabs {
    display: grid;
    grid-template-columns: repeat(2,1fr);
}
}

 

The code works great for the columns; however when I click on an item in the list it not only opens itself but another item as well. Can you check the glitch out and let me know if there's any code to correct this?

https://www.thehost.co/product-recommendations

 

Link to comment
On 1/13/2022 at 5:42 AM, laurensmithart said:

The code works great for the columns; however when I click on an item in the list it not only opens itself but another item as well. Can you check the glitch out and let me know if there's any code to correct this?

https://www.thehost.co/product-recommendations

 

Remove above & try this new code

/* product recommendations */
@media screen and (min-width:768px) {
.tabs {
    column-count: 2;
}
}

 

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
  • 1 month 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.