对于css实现水平垂直居中的方法,在前端开发中涉及的也比较多,在开发中经常使用的是flex布局以及绝对定位来实现居中方式,其实懂个三四种实现方式已经足够,但是这里将这些方法总结一下,这里只包括容器水平垂直居中的总结,可能不适用于图片文字等,图片字体的垂直居中其实也可以在下面的方法找到解决方式。
方法一:
See the Pen hv-center-1 by LCINA (@LCINA) on CodePen.
方法二:
See the Pen hv-center-2 by LCINA (@LCINA) on CodePen.
方法三:
See the Pen hv-center-3 by LCINA (@LCINA) on CodePen.
方法四:
See the Pen hv-center-4 by LCINA (@LCINA) on CodePen.
方法五:
See the Pen hv-center-5 by LCINA (@LCINA) on CodePen.
方法六:
See the Pen hv-center-6 by LCINA (@LCINA) on CodePen.
参考链接:用css让一个容器水平垂直居中