the_
the_

Reputation: 1173

Center a div that is inline-block

I have a .container div that I want to center on the page.

Unfortunately, the div is supposed to fit the table that is in inside. So if the table is at 75% of the page, I want the .container to be at 75% as well.

My .container looks like this:

.container{
  display:inline-block;
  background:#FFF;
  height:500px;
  max-width:80%;
}

I made a JSFiddle here.

Thanks for all help!

Upvotes: 1

Views: 71

Answers (1)

Josh Crozier
Josh Crozier

Reputation: 240868

Adding text-align:center to the parent of an inline-block element will center it.

Updated jsFiddle here

In this case, it would be:

body {
    text-align:center;
}

Upvotes: 1

Related Questions