我网页的左侧容器上有一个 Accordion ,默认情况下是左对齐的。我正在使用 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;
关于javascript - 如何在 CSS 中将 Accordion 居中对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41962147/