How to horizontally center multiple divs in a parent div

I am trying to create a control that contains multiple divs and all divs have horizontal center alignment. as shown below.

enter image description here

I was able to float each div using the float:left css property. which give something like this

enter image description here

but divs always stay at home.

I have one alternative solution to use javascript to place each div, but I want to use css. Is it possible to achieve this with css.

Thanks in advance

+5
source share
1 answer

This can do what you are trying to do:

HTML:

 <div class="parent"> <div class="child">Element 1</div> <div class="child">Element 2</div> </div> 

CSS

 .child { display: inline-block; } .parent { text-align: center; } 

and a violin .

+11
source

Source: https://habr.com/ru/post/1210484/


All Articles