What methods are there to achieve vertical centering in css?

王林
Release: 2020-03-23 10:31:13
forward
2570 people have browsed it

What methods are there to achieve vertical centering in css?

The method to achieve vertical centering in css is as follows:

1. Use line-height to achieve centering. This method is suitable for pure text;

  
   
css布局,实现垂直居中
Copy after login

Effect:

What methods are there to achieve vertical centering in css?

(Recommended tutorial:CSS tutorial)

2. By setting the relative positioning of the parent container, the child Absolute positioning is set at the level, and the label is adaptively centered through margin;

  
   
css布局,实现垂直居中
Copy after login

Effect:

What methods are there to achieve vertical centering in css?

3. Flexible layout flex parent setting display: flex; Set the margin of the child to auto to achieve adaptive centering;

  
   
css布局,实现垂直居中
Copy after login

Effect:

What methods are there to achieve vertical centering in css?

4. The parent sets relative positioning and the child sets absolute positioning. , and achieved through displacement transform;

  
   
css布局,实现垂直居中
Copy after login

Effect:

What methods are there to achieve vertical centering in css?

5. The parent sets the elastic box and sets the related properties of the elastic box;

  
   
Copy after login

Effect:

What methods are there to achieve vertical centering in css?

6. Grid layout, the parent is converted into table form, and then the child is implemented by setting inline or inline blocks. (It should be noted that the prerequisite for the use of vertical-align: middle is inline elements and elements with a display value of table-cell).

Effect:

What methods are there to achieve vertical centering in css?

  
   
Copy after login

Related video tutorial recommendation:css video tutorial

The above is the detailed content of What methods are there to achieve vertical centering in css?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
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
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!