How to horizontally center a
in another
?


Here I have one html form and one css file(style.css).”o-div” is the outer div and “i-div“is the inner div class.

Example

<html >
   <head>
      <title>center a div</title>
      <link href="../../Content/style.css" rel="stylesheet" type="text/css" />
   </head>
   <body>
      <div class="o-div">
         I am OUTER DIV

         <div class="i-div">
            I am INNER DIV,
            I am in Center

         </div>
      </div>
   </body>
</html>

Output

I am OUTER DIV
I am INNER DIV, I am in Center

Style.css

body {
   background-color:Gray;
   padding:30px;
}

.o-div {
   padding:50px;
   background-color:Lime;
}

.i-div {
   background-color:Fuchsia;
   max-width:400px;
   height:200px;
   margin: 0 auto;
   text-align:center;
}

Updated on: 22-Dec-2021

188 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements