javascript - Accordion within Accordion -
i trying embedded accordion within accordion it's not working, embedded accordion expand size of first expand accordion, need add space in order show content, appreciated!
css
button.accordion { background-color: #73560b; border: 2px solid #ffc600; border-radius: 0px 10px 0px 10px; box-shadow: 7px 7px 5px #cccccc; color: #fff; cursor: pointer; padding: 10px 15px 10px 15px; margin: 4px 0px 7px 0px; width: 100%; font-size: 18px; transition: 0.4s; outline: none; text-align: left; } button.accordion.active, button.accordion:hover { background-color: #926c0e; } button.accordion:after { content: '\002b'; color: #ffc600; font-weight: bold; float: right; } button.accordion.active:after { content: "\2212"; } div.panel { padding: 0 18px; background-color: white; max-height: 0; overflow: hidden; transition: max-height 0.2s ease-out; }
html
<button class="accordion">background</button> <div class="panel"> content <button class="accordion">item 1</button> <div class="panel"> content </div> </div>
javascript
var acc = document.getelementsbyclassname("accordion"); var i; (i = 0; < acc.length; i++) { acc[i].onclick = function() { this.classlist.toggle("active"); var panel = this.nextelementsibling; if (panel.style.maxheight){ panel.style.maxheight = null; } else { panel.style.maxheight = panel.scrollheight + "px"; } } }
var acc = document.getelementsbyclassname("accordion"); var i; (i = 0; < acc.length; i++) { acc[i].onclick = function(){ this.classlist.toggle("active"); var panel = this.nextelementsibling; if (panel.style.display === "block") { panel.style.display = "none"; } else { panel.style.display = "block"; } } }
button.accordion { background-color: #eee; color: #444; cursor: pointer; padding: 18px; width: 100%; border: none; text-align: left; outline: none; font-size: 15px; transition: 0.4s; } button.accordion.active, button.accordion:hover { background-color: #ddd; } div.panel { padding: 0 18px; display: none; background-color: white; }
<!doctype html> <html> <head> </head> <body> <h2>accordion</h2> <button class="accordion">section 2</button> <div class="panel"> <button class="accordion">section 1</button> <div class="panel"> <p> content </p> </div> </div> <button class="accordion">section 3</button> <div class="panel"> <p>lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 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.</p> </div> </body> </html>
try this
Comments
Post a Comment