How to center text in html

藏色散人
Release: 2023-01-06 11:16:17
Original
86179 people have browsed it

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文字水平上下居中
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!