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


這裡有一個 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

244 次瀏覽

開啟你的職業

透過完成課程獲得認證

開始
廣告