Home > Web Front-end > CSS Tutorial > Implementation code for css that does not fix width, height, and vertical centering

Implementation code for css that does not fix width, height, and vertical centering

小云云
Release: 2018-02-28 10:49:53
Original
1537 people have browsed it


本文主要和大家分享css不固定宽高垂直居中的实现代码,希望能帮助到大家。
一、

父元素:
display: flex;
justify-content: center;
align-items: center;


二、

父元素:
position: relative;

元素:
transform: translate(-50%, -50%);
position: absolute;
top: 50%;
left: 50%;


三、   		
display: table;需要有一个中间层,垂直居中元素为第三层

(1)
父元素的父元素:
display: table;

父元素:
display: table-cell;
text-align: center;
vertical-align: middle;

元素:
display: inline-block;


(2)

父元素的父元素:
display: table;

父元素:
display: table-cell;
vertical-align: middle;

元素:
margin: auto;
Copy after login

Related recommendations:

css vertical centering implementation code

Four css vertical centering methods

Solution to CSS vertical centering

The above is the detailed content of Implementation code for css that does not fix width, height, and vertical 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