Home >Web Front-end >CSS Tutorial >Implementation code for css that does not fix width, height, and vertical centering
本文主要和大家分享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;
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!