CSS中如何让色块居中呢?实际上有很多种方法,下面我们就一起来看看。首先,我们需要先创建一个色块: 接着,我们可以通过以下几种方法实现让色块居中的效果。 第一种方法:使用textalign属性 .c...
CSS中如何让色块居中呢?实际上有很多种方法,下面我们就一起来看看。
首先,我们需要先创建一个色块:
<div class="color-block"></div> <style>
.color-block{
width: 100px;
height: 100px;
background-color: #f00;
text-align: center;
}
</style> <style>
.color-block{
width: 100px;
height: 100px;
background-color: #f00;
margin: 0 auto;
}
</style> <style>
.container{
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.color-block{
width: 100px;
height: 100px;
background-color: #f00;
}
</style>
<div class="container">
<div class="color-block"></div>
</div>