Home  >  Article  >  Web Front-end  >  How to set vertical centering in css

How to set vertical centering in css

青灯夜游
青灯夜游Original
2021-04-21 17:08:2158121browse

How to set vertical centering in css: 1. Use the line-height attribute to center the text vertically; 2. Use CSS3 flex layout to center the text vertically; 3. Use absolute positioning and transform to center the block elements vertically; 4. Use flex layout to vertically center block elements.

How to set vertical centering in css

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

css sets the text to be vertically centered

1. Line-height makes the text vertically centered





css 垂直居中


css 垂直居中了--文本文字

Rendering:

How to set vertical centering in css

This will allow the text in the div to be centered horizontally and vertically

2. CSS3 flex layout Center the text vertically





css 垂直居中


css 垂直居中--文本文字(弹性布局)

Rendering:

How to set vertical centering in css

css sets block elements to be vertically centered

1. Use absolute positioning and transform (unknown element height)

If we don’t know the height of the element, then we need to position the element first The center position of the container, and then use the translate attribute of transform to coincide the center of the element with the center of the parent container to achieve vertical centering:





css 垂直居中


css 垂直居中,css 垂直居中,css 垂直居中,css 垂直居中,css 垂直居中

Rendering:

How to set vertical centering in css

2. Use flex layout





css 垂直居中


css 垂直居中了--弹性布局

Rendering:

How to set vertical centering in css

(Learning video sharing: css video tutorial )

The above is the detailed content of How to set vertical centering 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