HTML horizontal and vertical center

The centering technique is often used when designing web pages. Whether it’s text or pictures, there will always be such a need to match typesetting (If you want to use CSS DIV for typesetting, you can refer to this article: CSS DIV Centering), this article divides HTML centering techniques into two different directions, horizontal and vertical, as examples.


1. HTML horizontal center
<table width="300" height="80">
 <tr><td align="center">HTML horizontal center</td></tr>
</table>
The results are presented as

HTML horizontal center

You can see that in the HTML table, we set the td tag align="center" to indicate that things in td need to be centered horizontally. On some browsers, even the vertical centering is done for you, but in order to avoid Some browsers only have horizontal centering, and the vertical direction is up or down. It is best to add valign to handle the vertical direction.

2, HTML vertical center
<table width='"300" height="80">
 <tr><td align="center" valign="center">HTML horizontal center</td></tr>
</table>
The results are presented as

HTML horizontal center

In the second example, in addition to align="center", we also added valign="center" to declare that the vertical direction must also be centered.

Post a Comment

0 Comments