krupal patel krupal patel - 2 months ago 6
CSS Question

How to centering a div horizontally without width in old version browsers

How to centering a div horizontally without width in old version browsers which are not supported display:inline-block property.

How to centering my .container div horizontally without width

<div class="main_section">
<div class="content_wrapper">
<div class="container">My content</div>
</div>
</div>

Answer

Make the content you want to center (.container) inline-block. This way you can center it with text-align: center on the parent div.

.container {
  display: inline-block;
  background-color: red;
}

.content_wrapper {
  background-color: blue;  
  text-align: center;
}
<div class="main_section">
  <div class="content_wrapper">
    <div class="container">My content</div>
  </div>
</div>