Home > Article > Web Front-end > How to center text in div in css
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.
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:
<html> <head> <style type="text/css"> div { width: 200px; border: 1px solid red; text-align: center; } </style> </head> <body> <div> 示例文字 </div> </body> </html>
The effect is as follows:
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!