How To Center A Table In HTML - Computer Hope
Có thể bạn quan tâm
A table is an excellent way to present a lot of information in an organized way. Sales data, web page traffic, stock market trends, and student's grades are examples of information that are often presented in tables.
When adding a table to a web page using HTML (hypertext markup language), it may be more visually appealing to center it on the page. Centering text and pictures is usually done via the text-align class or through CSS (cascading style sheets), but centering a table requires a different approach. Details are provided below for how to center a table on a web page.
Centering a table in HTML
When adding a table to a web page, by default, it's aligned to the left side of the page or container, as shown below.
HITS | MONTH | TOTAL INCREASE |
324,497 | January 1998 | - |
436,699 | February 1998 | 112,172 |
The HTML source code for the table above is the following.
<table style="border:1px solid black"> <tr> <td><b>HITS</b></td> <td><b>MONTH</b></td> <td><b>TOTAL INCREASE</b></td> </tr> <tr> <td>324,497</td> <td>January 1998 </td> <td style="text-align:center">-</td> </tr> <tr> <td>436,699</td> <td>February 1998</td> <td style="text-align:center">112,172</td> </tr> </table>To center this table, you would need to add ;margin-left:auto;margin-right:auto; to the end of the style attribute in the <table> tag. The table tag would look like the following.
<table style="border:1px solid black;margin-left:auto;margin-right:auto;">Changing the style attribute in the <table> tag, as shown above, results in the table being centered on the web page, as shown below.
HITS | MONTH | TOTAL INCREASE |
324,497 | January 1998 | - |
436,699 | February 1998 | 112,172 |
You can add parameters to the style attribute in the <table> tag to make the table more eye appealing. Adding padding:2px; and border-spacing:20px; adds spacing between the data points and the border to improve readability.
Related information
- How to align text on a web page in HTML or CSS.
- Additional help and information with HTML tables.
- See our table page for related information and links.
- HTML and web design help and support.
- HTML and web design help.
Từ khóa » Html Center Column In Table
-
How To Center Align Text In Table Cells In HTML? - Tutorialspoint
-
CSS Table Alignment - W3Schools
-
How To Center The Contents Of An HTML Table? - Stack Overflow
-
How To Center The Text In The HTML Table Row - W3docs
-
Center A Table With CSS - Scott Granneman
-
(Archives) HTML: Tables: Alignment Within A Table | UW-Eau Claire
-
» - HTML">
» - HTML How To Center A Table With CSS (Quick Guide) - WpDataTables
Advanced Table Settings: Column Width, Alignment And Merging Cells
Vertical-align - CSS: Cascading Style Sheets - MDN Web Docs
: The Table Column Element - HTML - MDN Web Docs - Mozilla Specifying Horizontal Text Alignment For Cross Table Cells
How To Place Table Text Into Center Using Bootstrap? - GeeksforGeeks
Table Size & Alignment : MGA - Web Development Tutorials
Copyright © 2022 | Thiết Kế Truyền Hình Cáp Sông Thu