There are two better solutions
display: inline-block;
OR
display: table;
Out of these two display:table;
is better, because display: inline-block;
adds an extra margin.
For display:inline-block;
you can use the negative margin method to fix the extra space