Home >Web Front-end >CSS Tutorial >How to center text in div in css

How to center text in div in css

藏色散人
藏色散人Original
2021-02-05 09:19:557589browse

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:

<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:

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!

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