简体   繁体   中英

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!

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM