How to center text in div in css

藏色散人
Release: 2022-12-30 11:13:50
Original
7380 people have browsed it

The implementation method of displaying text in the center of a div in css: first create an HTML sample file; then add the div text to the body; finally, set the Chinese div by adding the "text-align:center" style to the div where the text is located. Just center the words.

How to center text in div in css

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

You can set the Chinese text in the div to be centered by adding the text-align:center style to the div where the text is located.

The text-align attribute specifies the horizontal alignment of text within an 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.

Attribute value:

  • left Arrange text to the left. Default: determined by the browser.

  • #right Align text to the right.

  • center Center the text.

  • justify achieves the effect of aligning text on both ends.

  • inherit specifies that the value of the text-align attribute should be inherited from the parent element.

Recommendation: "css video tutorial"

Example:

   
示例文字
Copy after login

The effect is as follows:

How to center text in div in css

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

Related labels:
css
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!