简体   繁体   English

手风琴按钮未隐藏的文本

[英]accordion button unhidden text

hi I am building a button where hide/show content when click on, however when I apply some styles to the content it won't hide anymore, I suspect it has got something to do with the css position, but can't figure it out why, could someone please help me? 嗨,我正在构建一个按钮,单击时可以隐藏/显示内容,但是当我对内容应用某些样式时,它将不再隐藏,我怀疑它与css位置有关,但无法弄清楚为什么,有人可以帮我吗? thanks in advance 提前致谢

  var acc = document.getElementsByClassName("accordion"); var i; for (i = 0; i < 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"; } } } 
  button.accordion { background-color: #13294b; border: 2px solid #59cbe8; 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: #1f447b; } button.accordion:after { content: '\\002B'; color: #59cbe8; font-weight: bold; float: right; } button.accordion.active:after { content: "\\2212"; } .panel { padding: 0 18px; background-color: white; max-height: 0; overflow: hidden; transition: max-height 0.2s ease-out; } .action1 { position: absolute; margin-top: -115px; margin-left: 35px; width: 100%; color: #c1c1c1; font-size: 14px; font-weight: bold; } .action2 { position: absolute; margin-top: -115px; margin-left: 175px; width: 100%; color: #c1c1c1; font-size: 14px; font-weight: bold; } 
  <button class="accordion">This is the button</button> <div class="panel"> <p><img width="650" height="114" style="border: 0px solid rgb(0, 0, 0); border-image: none;" src="./?a=654193" /><br /></p> <p class="action1">Recognise</p> <p class="action2">Remove from play</p> </div> 

Your paragraphs are absolute ly positioned, but not relative to the panel that is hiding/showing. 您的段落absolute处于absolute位置,但相对于隐藏/显示的面板而言并非absolute To position those relative to .panel , add position: relative to .panel , and the paragraphs will hide/show with `.panel. 要定位那些相对.panel ,添加position: relative.panel ,以及段落将隐藏/显示用`.panel。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM