An alternative is to work with flexbox. And for one simple reason: You don’t have to worry about the question of vertical and horizontal positioning, the property does all the work based on the rules defined.
An example:
.size-x {
height: 100px;
width:100px;
}
.circle {
background: #333;
color: #fff;
border-radius: 50%;
font-size: 2em;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
justify-content: center;
}
<div class='size-x circle'>1</div>
At first it may seem a lot of code for something so simple, it turns out it is still an "experimental" property, so you need to use some prefixes.
But to show the question of "don’t worry about the alignment (...) flexbox take care of it" here are some examples increasing only the width
and height
of the same class used in the above example:
.circle {
background: #333;
color: #fff;
border-radius: 50%;
font-size: 2em;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
justify-content: center;
}
.size-u {
background: #1abc9c;
height: 50px;
width: 50px;
}
.size-v {
background: #3498db;
height: 100px;
width: 100px;
}
.size-w {
background: #9b59b6;
height: 150px;
width: 150px;
}
.size-x {
background: #e74c3c;
height: 200px;
width: 200px;
}
.size-y {
background: #f1c40f;
height: 300px;
width: 300px;
}
.size-z {
background: #34495e;
height: 500px;
width: 500px;
}
<div class='size-u circle'>1</div>
<div class='size-v circle'>2</div>
<div class='size-w circle'>3</div>
<div class='size-x circle'>4</div>
<div class='size-y circle'>5</div>
<div class='size-z circle'>6</div>
Perfect! : D :D
– Silvio Andorinha