[英]How to align center an accordion in CSS?
我的网页左侧容器上有一个手风琴,默认情况下该手风琴保持左对齐。 我正在使用CSS使其居中对齐。 我已经尝试在CSS代码中使用position:center,align:left和margin-left:5px,但是这些都不起作用。 谁能帮我吗。 提前致谢。
这是我的CSS代码:
var acc_leftpanel = document.getElementsByClassName("accordion_leftpanel"); var i; for (i = 0; i < acc_leftpanel.length; i++) { acc_leftpanel[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_leftpanel { background-color: #2da0d9; color: #444; cursor: pointer; padding: 5px; width: 60%; border: none; align: center; text-align: center; outline: none; font-size: 12px; transition: 0.4s; border-radius: 25px; } button.accordion_leftpanel.active, button.accordion_leftpanel:hover { background-color: #5ebb61; } button.accordion_leftpanel:after { color: #ffffff; font-weight: bold; float: center; margin-left: 8px; }
<div class="leftcontentborder"> <p align="center">LIST OF SOLVED PAPERS</p> <button class="accordion_leftpanel" align="center">June 2014</button> <div class="panel"> <p>Paper 2</p> <p>Paper 3</p> </div> </div>
中心使用保证金, margin: 0 auto;
如果您想将所有内容置于leftcontentborder
中心,则可以在CSS中添加一个类。
.leftcontentborder {
text-align: center;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.