当子元素定宽定高
absoluted +relative ,flex也可以
- 方法一:
绝对定位absoluted
父元素:relative
子元素:absoluted +top,bottom,left,right:0;+margin:auto
- 方法二:
绝对定位absoluted
父元素:relative
子元素:absoluted ;+top,left:50%;+margin-left:-(width/2);margin-top:-(height/2px);
- 方法三:
绝对定位absoluted
父元素:relative
子元素:absoluted ;+top:calc(50%-(width/2));left:cacl(50%-(height/2px));
子元素没有定宽定高
flex,line-height
- 方法四:同样适用子元素定宽定高
flex
父元素:flex;(水平方向居中)justify-content:center;(垂直方向居中)align-items-center; - 方法五:
line-height
父元素:
line-height:父元素高度;//实现子元素垂直居中
t