Home  >  Article  >  Web Front-end  >  How to center text in html

How to center text in html

藏色散人
藏色散人Original
2021-06-03 10:21:0686128browse

htmlMethods to center text: 1. Set the text to be centered horizontally through the "text-align:center;" attribute; 2. Set the text to be vertically centered through the "line-height:height;" attribute.

How to center text in html

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

The specific example of the html text centering code is as follows:




 html文字居中测试
 
 

html文字水平居中
html文字垂直居中
html文字水平上下居中

The effect of the above code is tested locally as shown below:

How to center text in html

Remember these key points , in HTML, the css code to center the text:

1. Horizontal centering: text-align:center; The

text-align attribute specifies the horizontal alignment of the text in the element.

This attribute sets the horizontal alignment of text within block-level elements by specifying the point at which the line box is aligned. The value justify is supported by allowing user agents to adjust the spacing between letters and words in line content; different user agents may get different results.

2. Vertical centering: line-height:height;

The line-height property sets the distance between lines (line height).

Note: Negative values ​​are not allowed.

【Recommended learning: html video tutorial

The above is the detailed content of How to center text in html. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn