Home  >  Article  >  Web Front-end  >  How to set css font to be centered in a single line

How to set css font to be centered in a single line

藏色散人
藏色散人Original
2020-12-30 09:28:022916browse

How to set a single line of CSS fonts to be centered: first create a div; then write a p tag in the div; finally, set the "text-align: center;" attribute to achieve single line centering.

How to set css font to be centered in a single line

The operating environment of this tutorial: Dell G3 computer, Windows 7 system, HTML5&&CSS3 version.

css Set the font to be centered in a single line

1. First, for the convenience of observation, create a div


How to set css font to be centered in a single line

2. Then write a p tag in the div and set its text-align: center; attribute to center a single line.


Hello World!

How to set css font to be centered in a single line

3. If it is an inline element such as span, you can add the text-align: center; attribute to its parent element


Hello World!

4. To achieve vertical centering of a single line of text, just set line-height to be the same as the height of the parent element.


Hello World!

How to set css font to be centered in a single line

Recommended: "css video tutorial"

The above is the detailed content of How to set css font to be centered in a single line. 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