Существует несколько способов центрирования блока в CSS по центру:
- С помощью свойства margin и значения auto:
.block {
width: 200px;
height: 200px;
margin: auto;
}
- С помощью свойства display и значения flex:
.container {
display: flex;
justify-content: center;
align-items: center;
}
.block {
width: 200px;
height: 200px;
}
- С помощью свойства position и значения absolute:
.container {
position: relative;
}
.block {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
- С помощью свойства text-align и значения center:
.container {
text-align: center;
}
.block {
display: inline-block;
}