CSS: Won't center div with max-width

Anton Belev picture Anton Belev · Aug 1, 2013 · Viewed 38.1k times · Source

I've got the following page structure:

<div class="main-container">
    <div class="content">
        <table>

        </table>
    </div>
</div>

I want the outher div main-container to have max-width: 800px; and the inner div to be wrapped around a table and to have the same with as the table. Also <div class="content"> should be centered inside his parent div - main-container. What am I doing wrong here? jsfiddle

Working example: jsfiddle

Answer

Gideon Rosenthal picture Gideon Rosenthal · Mar 9, 2015

I had a similar issue. Setting

margin-left: auto;
margin-right: auto;

on the inner div worked for me.