我的网页左侧容器上有一个手风琴,默认情况下左对齐。我正在使用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>
答案 0 :(得分:1)
使用保证金margin: 0 auto;
答案 1 :(得分:0)
如果要将所有内容放在leftcontentborder
内,可以在CSS中添加一个类。
.leftcontentborder {
text-align: center;
}