如何实现对中效果:
1、用absolute取负边距
father{ position: relative; //父要素设定绝对位置} .son{ position: absolute; width:100px; height:100px; top: 50%; left: 50%; 边距左边缘:-50px; 边距-顶部:-50px; ) 2、absolute合并自动
. father{ position: relative; //父要素设定绝对位置} .son{ position: absolute; top: 0; left: 0; right: 0; bottom: 0; 边距:自动; } 3、absolute transform
. father{ position: relative; //父要素设定绝对位置} .son{ position: absolute; top: 50%; left: 50%; transform:translate(-50%、-50%; (4、absolute calc、
. father{ position: relative; //父要素设定绝对位置} .son{ position: absolute; width:100px; height:100px; top:calc(50%-50px; left:calc(50%-50px ); ) 5、弹性布局
. father{ display: flex; 内容:中心; /*显示在主轴中间*/align-items: center; /*子项位于侧轴的中间位置*/} 6、网格布局
. father{ display:grid; align-items3360中心; Justify-items3360中心; (7、由css添加的表属性
. father { display: table-cell; 文本照明3360中心; vertical-align :中间; } .son { display: inline-block; (8、text-align和line-height
. father {文本对齐:中心; width: 100px; height: 100px; background :身份识别; line-height: 100px; () ) ) ) )。