簡體   English   中英

如何將內容對齊到 html 頁面的中心

[英]How to align contents to the centre of html page

我有以下 html 代碼

 <body> <h3>Title 1</h3> <h3>Title 2</h3> <div> <a href="ref1"> <button type="button">Button 1</button> </a> <span> abcd </span> <a href="ref2"> <button type="button">Button 2</button> </a> </div> <div> <table> <tr> <th>Col1</th> <th>Col2</th> <th>Col3</th> </tr> <tr> <td>value1</td> <td>value2</td> <td>value3</td> </tr> </table> </div> </body>

我想將 css 添加到以下以按以下格式與頁面居中對齊

                      title 1
                      title 2
              button1  abcd  button2
          +----------------------------+
          |   col1 |   col2  |  col3   |
          +----------------------------+
          |   val1 |   val2  |  val3   |
          +----------------------------+

表格和標題應位於頁面中心。 並且帶有按扣的 2 個按鈕應該在同一條線上,並且中心對齊。 我怎樣才能做到這一點?

將以下樣式應用於 body 標簽 display:flex; 證明內容:中心;

將以下樣式添加到 html 頂部的主體標簽。

<body style="text-align: center; display: grid; justify-content:center;">

 <body> <center> <h3>Title 1</h3> <h3>Title 2</h3> <div > <a href="ref1"> <button type="button" >Button 1</button> </a> <span> abcd </span> <a href="ref2"> <button type="button" >Button 2</button> </a> </div> <div > <table > <tr> <th>Col1</th> <th>Col2</th> <th>Col3</th> </tr> <tr> <td>value1</td> <td>value2</td> <td>value3</td> </tr> </table> </div> </center> </body>

使用 HTML center標簽將身體的全部內容對齊到中心。

使用 CSS GRID 那你為什么要使用 table 呢?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM