CMS Development

Ohhcoconut
Contributor

Styling more than one accordion by div?

SOLVE

Hi,

I have an accordion built for my customer lists and I am desiring to have another accordion built but in a different style to allow for my FAQ to be neatly organized. My issue is I do not know how to write code for more than one class so I can have two different accordions but not have them use the same styling.

 

Here is the style of the accordion I am trying to use as my FAQ.

https://jsfiddle.net/ohhcoconut/7vsyu756/

 

Below is the styling for my customer list accordion

https://jsfiddle.net/ohhcoconut/g6113znb/2/

 

Any help would be great! Thank you.

 

0 Upvotes
1 Accepted solution
Jsum
Solution
Key Advisor

Styling more than one accordion by div?

SOLVE

@Ohhcoconut,

 

HTML is document structure code.

CSS styles or applies aesthetics to the page. While there are css animation styles it's best when starting out to not consider these.

Javascript is the equivilant of a programming language such as Java, Python, C++, etc. but is the only programming language that works natively with the browser.

JQuery is a library created from javascript that is mostly for DOM manipulation. It's purpose is to be easier to use than javascript, but it is still javascript. 

 

If your dropdown is not working it is most likely because of javascript. Either you do not have a script installed for the FAQ drop down to work or, if you do, your html elements are not properly structured, Id'd, or classed. You should first find the script then try to understand how it works. Most scripts you find on the internet come with documentation explaining how to set up your html. 

View solution in original post

0 Upvotes
7 Replies 7
Jsum
Key Advisor

Styling more than one accordion by div?

SOLVE

@Ohhcoconut,

 

You wrap your accordians in wrapper divs.

<div class="wrapper-1">
    ****accordian HTML****
</div>

<div class="wrapper-2">
    ****accordian HTML***
</div>

and then use the wrapper classes to for specific styling

.wrapper-1 .accordian {
    ***accordian 1 styles****
}

.wrapper-2 .accordian {
    ***accordian 2 styles****
}

and leave the structural styling under the .accordian style without a parent.

Ohhcoconut
Contributor

Styling more than one accordion by div?

SOLVE

Hi  @Jsum

Thank you for that info. Now my execution is needing some help. If we focus on just styling one CSS, note as below:

.wrapper-1.accordion { 

.accordion,
.accordion * {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.accordion {
  /*box-shadow:0px 1px 3px rgba(0,0,0,0.25); Comment out by HS support 4/13/17 */
  border-radius: 3px;
  background: #ffffff;
  position: absolute;
}


/*----- Section Titles -----*/

.accordion-section-title {
  width: 100%;
  padding: 5px;
  display: inline-block;
  border-radius: 15px 15px 15px 15px;
  /*15px 15px 15px 15px; HS SUPPORT*/
  border-bottom: 1px solid #1a1a1a;
  background: #29cdcb;
  transition: all linear 0.15s;
  /* Type */
  font-size: 1.200em;
  font-weight: bold;
  text-align: center;
  text-shadow: 0px 1px 0px #1a1a1a;
  color: #fff;
  text-decoration: none;
}

.accordion-section-title.active,
.accordion-section-title:hover {
  background: #800000;
  color: #fff;
  /* Type */
  text-decoration: none;
}

.accordion-section:last-child .accordion-section-title {
  border-bottom-color: white;
  padding-bottom: 2px;
}


/*----- Section Content -----*/

.accordion-section-content {
  height: 100%;
  max-height: 500px;
  /* Y axis is scrollable */
  overflow-y: scroll !important;
  /* X axis is cropped */
  overflow-x: hidden;
  padding: 0;
  display: none;
  border: .5px solid gray;
}
}

 

So essentially I am trying to wrap that first line to the end line in the .wrapper-1.

Here is my html.

<div class=".wrapper-1.accordion">
  <div class="accordion-section">
    <a class="accordion-section-title" href="#accordion-1">
  Phoenix Participants List
     
 </a>

    <div id="accordion-1" class="accordion-section-content">

      <p>
        <ul>Ak-Chin Southern Dunes</ul>
        <ul>Antelope Hills- North</ul>
        <ul>Antelope Hills- South</ul>
        <ul>Arizona Grand Resort</ul>
              </p>


    </div>
    <!--end .accordion-section-content-->
  </div>
  <!--end .accordion-section-->
</div>
<!--end .accordion-->

I am playing is JSFiddle just until I truly get the concept and mess around in my hubspot code.

 

Thank you!

0 Upvotes
Jsum
Key Advisor

Styling more than one accordion by div?

SOLVE

@Ohhcoconut,

 

I see one issue. Your classes aren't applied correctly here:

<div class=".wrapper-1.accordion">

it should be

<div class="wrapper-1 accordion">

no periods and spaces between class names. see if that helps.

 

Also it looks like you are nesting css. You have all of your css insde the wrapper-1 css. are you using sass or scss? I don't think you can use nesting in regular css.

0 Upvotes
Ohhcoconut
Contributor

Styling more than one accordion by div?

SOLVE

Thanks for your help @Jsum,

I took out those periods in HTML and my fiddle isnt doing what I want. The content is there, it doesn't contain to the pillbox accordion traditional style before I added the wrapper.

 

Nesting? I don't know if I use sass or scss. I'm writing the code in basic JSFiddle and the basic Hubspot program.

 

If I can't nest it (which I'm guessing is when you wrap the div with the .wrapper-1.accordion{ } which is what I tried to do with the CSS) do you have to write .wrapper-1._____ for every section of the accordion?

 

Thank you!

0 Upvotes
Jsum
Key Advisor

Styling more than one accordion by div?

SOLVE

@Ohhcoconut,

Copy and paste this into your css and see that your styles apply. You can't nest css unless you use a preprocessor like sass or scss that process your short coded css into real css. 

.wrapper-1.accordion { }

.accordion,
.accordion * {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.accordion {
  /*box-shadow:0px 1px 3px rgba(0,0,0,0.25); Comment out by HS support 4/13/17 */
  border-radius: 3px;
  background: #ffffff;
  position: absolute;
}


/*----- Section Titles -----*/

.accordion-section-title {
  width: 100%;
  padding: 5px;
  display: inline-block;
  border-radius: 15px 15px 15px 15px;
  /*15px 15px 15px 15px; HS SUPPORT*/
  border-bottom: 1px solid #1a1a1a;
  background: #29cdcb;
  transition: all linear 0.15s;
  /* Type */
  font-size: 1.200em;
  font-weight: bold;
  text-align: center;
  text-shadow: 0px 1px 0px #1a1a1a;
  color: #fff;
  text-decoration: none;
}

.accordion-section-title.active,
.accordion-section-title:hover {
  background: #800000;
  color: #fff;
  /* Type */
  text-decoration: none;
}

.accordion-section:last-child .accordion-section-title {
  border-bottom-color: white;
  padding-bottom: 2px;
}


/*----- Section Content -----*/

.accordion-section-content {
  height: 100%;
  max-height: 500px;
  /* Y axis is scrollable */
  overflow-y: scroll !important;
  /* X axis is cropped */
  overflow-x: hidden;
  padding: 0;
  display: none;
  border: .5px solid gray;
}

 What you want to do is put all of your base styling into the .accordian styling, then your apply specific styling to the specific wrappers:

.accordian,
.accordian * {
     -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
     box-sizing: border-box;
}

.accordian {
    position: absolute;
}

.wrapper-1 .accordian {
    border-radius: 3px;
    background: #ffffff;
}

.accordion-section-title {
    width: 100%;
    padding: 5px;
    display: inline-block;
    transition: all linear 0.15s;
    font-size: 1.200em;
    font-weight: bold;
    text-align: center;
    text-decoration: none;
}

.wrapper-1 .accordion-section-title {
    border-radius: 15px 15px 15px 15px;
    /*15px 15px 15px 15px; HS SUPPORT*/
    border-bottom: 1px solid #1a1a1a;
    background: #29cdcb;
    text-shadow: 0px 1px 0px #1a1a1a;
    color: #fff;
}

.accordion-section-title.active,
.accordion-section-title:hover {
    text-decoration: none;
}

.wrapper-1 .accordion-section-title.active,
.wrapper-1 .accordion-section-title:hover {
     background: #800000;
     color: #fff;
}

.wrapper-1 .accordion-section:last-child .accordion-section-title {
    border-bottom-color: white;
    padding-bottom: 2px;
}

.accordion-section-content {
      height: 100%;
      max-height: 500px;
      /* Y axis is scrollable */
      overflow-y: scroll !important;
      /* X axis is cropped */
      overflow-x: hidden;
      padding: 0;
      display: none;
}

.wrapper-1 .accordion-section-content {
      border: .5px solid gray;
}

I reorganized your css like what I am talking about. See how all base css is in the base class while specific css is assigned to wrapper-1?

Ohhcoconut
Contributor

Styling more than one accordion by div?

SOLVE

Thanks so much for your help, this project fell on the back burner.

I've given up on styling multiple accordions right now, I would rather just get this FAQ page to work. The code works great, the style is perfect. The only issue is that when I click on the button for the accordion, the content box does not drop down. Most outside forums discuss J Query in java script but I am only writing and hosting with hubspot and I'm unsure where that code would be. 

button.accordion {
    background-color: #eee;
    color: #444;
    cursor: pointer;
    padding: 18px;
    width: 100%;
    text-align: left;
    border: none;
    outline: none;
    transition: 0.4s;
    border-radius: 15px;
}

/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
button.accordion.active, button.accordion:hover {
    background-color: #29cdcb;
}

/* Style the accordion panel. Note: hidden by default */
div.panel {
    padding: 0 18px;
    background-color: white;
    display: none;
   border-radius: 15px;
}

Thanks!

0 Upvotes
Jsum
Solution
Key Advisor

Styling more than one accordion by div?

SOLVE

@Ohhcoconut,

 

HTML is document structure code.

CSS styles or applies aesthetics to the page. While there are css animation styles it's best when starting out to not consider these.

Javascript is the equivilant of a programming language such as Java, Python, C++, etc. but is the only programming language that works natively with the browser.

JQuery is a library created from javascript that is mostly for DOM manipulation. It's purpose is to be easier to use than javascript, but it is still javascript. 

 

If your dropdown is not working it is most likely because of javascript. Either you do not have a script installed for the FAQ drop down to work or, if you do, your html elements are not properly structured, Id'd, or classed. You should first find the script then try to understand how it works. Most scripts you find on the internet come with documentation explaining how to set up your html. 

0 Upvotes