ringa_lee2017-04-17 13:11:33
沒看你程式碼哈。
不過讓快元素居中,有多種方式:
1: display:inline-block
.total{width:1000px;height:auto;border:1px solid #ccc;text-align:center;}
.center{width:200px;height:50px;background-color:blue;display:inline-block;}
<p class='center'></p>
2: 未知寬高:position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);
.total{width:1000px;height:auto;border:1px solid #ccc;}
.center{width:200px;height:50px;background-color:blue;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);}
<p class='center'></p>
2: 已知寬高:width:200px;height:200px;position:absolute;left:50%;top:50%;transform:translate(-100px,-100px);
.total{width:1000px;height:auto;border:1px solid #ccc;}
.center{width:200px;height:50px;background-color:blue;position:absolute;left:50%;top:50%;transform:translate(-100px,-100px)}
<p class='center'></p>
以上程式碼未經測試,若有問題再問哈