How to align the image in the center vertically and horizontally without using CSS3 ? I made using text-align: center and margin-top: 10px; , but I don’t consider this option to be correct, as it’s always a matter of guessing what margin-top prescribe for the image to be centered is not an option.
Clean code, not aligned:
.icons { background: url('http://uxen.ru/images/css-sprite-combined.png?1') no-repeat; } .icons.plus { display: inline-block; background-position: -0px 0px; width: 10px; height: 10px; } .button_wrap { display: inline-block; width: 30px; height: 30px; background: #65d1e0; font-size: 0; cursor: pointer; } .button_wrap .button { } <div class="button_wrap"> <div class="button"> <div class="icons plus"></div> </div> </div> https://jsfiddle.net/g3mxLLm7/1/
Code with alignment, I think that it’s not quite right to use text-align: center and margin-top: 10px; :
.icons { background: url('http://uxen.ru/images/css-sprite-combined.png?1') no-repeat; } .icons.plus { display: inline-block; background-position: -0px 0px; width: 10px; height: 10px; } .button_wrap { display: inline-block; width: 30px; height: 30px; background: #65d1e0; font-size: 0; cursor: pointer; } .button_wrap .button { text-align: center; margin-top: 10px; } <div class="button_wrap"> <div class="button"> <div class="icons plus"></div> </div> </div>