Using tables in web design has an interesting history. Before CSS, tables were often used to control the entire page layout, not just to display tabular data in existing ways. At that time, HTML tables were used to define the structure and visual appearance of web pages, and the location of tables could be directly specified in HTML. For example, to center the sorting of a table, you can simply create the following: Male
And
However, sorting tables in this way is no longer correct and is no longer used in HTML5. Because modern web standards dictate the separation of structure (HTML) and style (CSS), the above approach violates the principle. The
You cannot use HTML to set how elements are displayed. This is the role of CSS. So, what is the correct way to center a table in CSS? This article by the wpdatatables team introduces some tips on how to handle this problem and arrange the tables correctly. Considering that we have created a great WordPress form plug-in, we know oneortwo about forms, so let’s take a closer look. How to use CSS to center a table? CSS sets the appearance of the page so that you can control the appearance and position of all elements, including table elements and all child elements such as th, TR and TD. The
First, let’s take a look at how to center a table using CSS. If the right and left margins are the same value, the latest browser must center the table. An easy way to do this is to automatically set two margins. An example of how to create it in CSS is as follows: table
The{
Right margin: automatic;
Blank – left: automatic;
}For example, you cannot center a table, just like using text align: Center to use text. This is because table elements are block level elements as opposed to inline elements. \
However, previous versions of Internet Explorer had errors, and block level elements were treated as inline elements. Therefore, the only way to center a table to work in some versions of IE is to explicitly set \
Text alignment: Center;
}\
The general format of the example is as follows: Male
Male
Male
Male style applies to male, male or sometimes both. The style sheet section for setting margins includes: Center1
The{
Right margin: automatic;
Blank – left: automatic;
}The
Center2
The{
Text alignment: Center;
}The
This example works well in the latest browsers. It also works with most older browsers. After using this method, open it in another browser to see its appearance. The
CSS:. Centertbl
The{
Text alignment: Center;
}The
Centertbl table
The{
Blank – left: automatic;
Right margin: automatic;
Text alignment: left;
}How does it work? The first part is placed in the male including the male. This will center the table in Internet Explorer 5 and Netscape 4. The second part applies to males within males. Margin settings