using flexbox, this is by far the best option, but now it is supported, for example, <10 http://caniuse.com/#feat=flexbox
If you need to work with browsers that do not support flexbox, horizontal alignment is easy, you can do this by adding an attribute display: inline on.circle and text-align: center on.row.
http://jsfiddle.net/BTh2t/2/
.circle { border-style: solid; border-color: red; height: 70px; width: 70px; border-radius: 40px; display: inline-block; margin: 2px; } .row { border-style: solid; border-color: black; height: 100px; width: 700px; margin: 10px; text-align: center; }
For vertical alignment, I can make it work using percentages for the height of the circle, and I change the window size property and the upper and lower margins, so the percentage value makes sense and assigns a position relative to the circle class, so we can use the upper property using half the remaining percentage ex: circle height = 70%, circle above = 15%
http://jsfiddle.net/BTh2t/3/
.circle { border-style: solid; border-color: red; height: 70%; width: 70px; border-radius: 40px; display: inline-block; margin-left: 2px; margin-right: 2px; position: relative; top: 15%; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; } .row { border-style: solid; border-color: black; height: 100px; width: 700px; margin: 10px; text-align: center; }
remember that with this approach, if you increase the height of the .row class, the height of the circle will increase automatically.
Hope this helps!
source share