tutorialpro 1

tutorialpro.org -- Learning is not just about technology, it's"> tutorialpro 1

tutorialpro.org -- Learning is not just about technology, it's" />

Easy Tutorial
❮ Verilog Tutorial Css Nav Bar ❯

JavaScript/CSS Implementation of Accordion/Collapse Effect

Category Programming Technology

Basic HTML Code

Example

<button class="accordion">tutorialpro 1</button>
<div class="panel">
  <p>tutorialpro.org -- Learning is not just about technology, it's about dreams!!!</p>
</div>

<button class="accordion">tutorialpro 2</button>
<div class="panel">
  <p>tutorialpro.org -- Learning is not just about technology, it's about dreams!!!</p>
</div>

<button class="accordion">tutorialpro 3</button>
<div class="panel">
  <p>tutorialpro.org -- Learning is not just about technology, it's about dreams!!!</p>
</div>

The following is the accordion collapse style:

Example

/* Styles for opening and closing the accordion panel */
.accordion {
  background-color: #eee;
  color: #444;
  cursor: pointer;
  padding: 18px;
  width: 100%;
  text-align: left;
  border: none;
  outline: none;
  transition: 0.4s;
}

/* Styles for active and hover states */
.active, .accordion:hover {
  background-color: #ccc;
}

/* Styles for the accordion panel. Hidden by default */
.panel {
  padding: 0 18px;
  background-color: white;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
}
/* Styles for the + and - signs */
.accordion:after {
  content: '\002B';  /* Unicode character for + sign */
  color: #777;
  font-weight: bold;
  float: right;
  margin-left: 5px;
}

.active:after { 
  content: "\2212";  /* Unicode character for - sign */
}

The following is the accordion collapse JavaScript code:

Example

var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
    acc[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var panel = this.nextElementSibling;
    if (panel.style.maxHeight) {
      panel.style.maxHeight = null;
    } else {
      panel.style.maxHeight = panel.scrollHeight + "px";
    } 
  });
}

** Click to Share Notes

Cancel

-

-

-

❮ Verilog Tutorial Css Nav Bar ❯