方法一: table法(只使用html实现垂直居中)
方法二:css中table法(在css里模拟table效果)
html端
css端
方法三:绝对居中法
css端
html端
显示效果
方法四: transform: translate(-50%,50%)法(绝对居中但不知道元素的宽高问题)
css端
html端
输出
方法五:margin
+ position:absolute
法
css端
html端
输出
方法六:margin-top: - height/ 2
法
html端
css端
输出
方法七:
4,如果想让文本换行,可以使用
- 使用
<br>
的情况:
- 不使用
<br>
的情况: