How to horizontally center a div inside a div using css

Share

Yes its very easy to center a block element inside other block element using simple css. Here is an example.

If you have following HTML code:

This is how we make innerDiv center horizontally.

.outerDiv{
width:100%
}
.innerDiv {
    width: 980px;
    margin: 0 auto;
}

if you are using IE8+ you have to do things like.

.innerDiv {
   display: table;
}
  • May 15, 2014
8 Best Free Stock Video Websites for Tiktok, Reels, and Shorts Top 5 PHP Frameworks: Fast and Secure