ringa_lee2017-04-17 13:11:33
没看你代码哈。
不过让快元素居中,有多种方式:
1: display:inline-block
<style>
1 2 | <code>.total{width:1000px;height:auto;border:1px solid #ccc;text-align:center;}
.center{width:200px;height:50px;background-color:blue;display:inline-block;}</code>
|
</style>
<p class='total'>
1 | <code><p class = 'center' ></p></code>
|
</p>
2: 未知宽高:position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);
<style>
1 2 | <code>.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%);}</code>
|
</style>
<p class='total'>
1 | <code><p class = 'center' ></p></code>
|
</p>
2: 已知宽高:width:200px;height:200px;position:absolute;left:50%;top:50%;transform:translate(-100px,-100px);
<style>
1 2 | <code>.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)}</code>
|
</style>
<p class='total'>
1 | <code><p class = 'center' ></p></code>
|
</p>
以上代码未经测试,若有问题再问哈
balas
0