The behavior you refer to is called accordion or Collapse.
See an example of Collapse with Bootstrap: http://www.w3schools.com/Bootstrap/bootstrap_collapse.asp
You can do it on hand, take this example:
http://www.w3schools.com/howto/howto_js_accordion.asp
Html
<button class="accordion">Section 1</button>
<div class="panel">
<p>Lorem ipsum...</p>
</div>
<button class="accordion">Section 2</button>
<div class="panel">
<p>Lorem ipsum...</p>
</div>
<button class="accordion">Section 3</button>
<div class="panel">
<p>Lorem ipsum...</p>
</div>
Css
button.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
text-align: left;
border: none;
outline: none;
transition: 0.4s;
}
button.accordion.active, button.accordion:hover {
background-color: #ddd;
}
div.panel {
padding: 0 18px;
background-color: white;
display: none;
}
div.panel.show {
display: block;
}
div.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: 0.6s ease-in-out;
opacity: 0;
}
div.panel.show {
opacity: 1;
max-height: 500px;
}
button.accordion:after {
content: '\02795';
font-size: 13px;
color: #777;
float: right;
margin-left: 5px;
}
button.accordion.active:after {
content: "\2796";
}
Javascript
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function(){
this.classList.toggle("active");
this.nextElementSibling.classList.toggle("show");
}
}
I couldn’t understand... be clearer please
– fernandoocf
Get it this way
– Maröb
You are looking for a Accordion. See if this is it and add your question, it will be easier to understand it like this
– Vinícius
An example with Sass and HTML only: https://codepen.io/abergin/pen/ihlDf
– Vinícius