[css] 写出div在不固定高度的情况下水平垂直居中的方法?
我知道的有两种方法<!DOCTYPE html>
<html><head><meta charset="utf-8"><title></title></head><style>* {padding: 0;margin: 0;}/* flex居中 */.tith1 {display: flex;justify-content: center;align-items: center;background: red;}/* table居中 */.tith2 {text-align: center;width: 100%;display: table;background: blue;}.tith2 > span {display: table-cell;vertical-align: middle;}</style><body><p class="tith1"><span>123</span></p><p class="tith2"><span>123</span></p></body>
</html>
个人简介
我是歌谣,欢迎和大家一起交流前后端知识。放弃很容易,
但坚持一定很酷。欢迎大家一起讨论
主目录
与歌谣一起通关前端面试题