如何在另一个
中水平居中
?


这里有一个 html 表格和一个 css 文件(style.css)。“o-div”是外部 div,“i-div”是内部 div 类。

示例

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

输出

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

更新于: 22-Dec-2021

245 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始学习
广告
© . All rights reserved.