Home > Article > Web Front-end > How to center the html basic frame code
HTML basic frame code centering method is as follows: 1. Use CSS to add the
{ text-align: center; } style inside the tag, which will center all text on the page. 2. Use thetag to wrap the content. 3. Use table elements (not recommended), but it violates the principle of semantics.
How to center the HTML basic frame code?
The method of centering the HTML basic frame code is as follows:
1. Use CSS
in <head>## Add the following CSS style inside the # tag:
<code class="css">body { text-align: center; }</code>This will center all text on the page.
2. Use the tag
tag to wrap the content to be centered:
<code class="html"><center> <h1>文本居中</h1> </center></code>
3. Use tables (not recommended)
Using table elements is also a method of centering elements, but it is not recommended because it violates the principle of semantics :<code class="html"><table> <tr> <td align="center">文本居中</td> </tr> </table></code>
Note: The
attribute can also be used on centered block elements (such as
tag can only be used on block elements. The default
text-align value for
elements is
left, while the
tag The default value is
center.
The above is the detailed content of How to center the html basic frame code. For more information, please follow other related articles on the PHP Chinese website!