How to set html text centering

青灯夜游
Release: 2021-06-03 16:30:34
Original
16426 people have browsed it

Method: 1. Use the style attribute in the label and add the "text-align:center;" style to set the text to be horizontally centered; 2. Use the style attribute to add "vertical-align:middle;display:table -cell;" style setting is vertically centered.

How to set html text centering

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

Method 1: Use the style attribute to add the "text-align:center;" style

HTML style attribute specifies the inline style of the element

css The text-align attribute specifies the horizontal alignment of the text in the element, by using the center value to set the text to be centered.

Example:

<p style="height: 100px; border: 1px solid red;text-align: center;">文本文字--水平居中</p>
Copy after login

Rendering:

How to set html text centering

##Method 2: Use the style attribute and add "vertical- align:middle;display:table-cell;” style

vertical-align:middle display:table-cell can center both single-line text and multi-line text. However, because table-cell is an inline type, it will cause the original block-level elements to be moved to the same row per div. If you need to divide the rows into two rows, you need to add an additional container outside to control the position.

Example:

<div   style="max-width:90%">
文本文字--垂直居中
</div>
Copy after login
Rendering:


How to set html text centering

(Learning video sharing:

css video tutorial )

The above is the detailed content of How to set html text centering. 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
Popular Tutorials
More>
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!