首页 > 编程知识 正文

如何实现水平垂直居中css,怎么实现水平垂直居中

时间:2023-05-05 02:52:24 阅读:185860 作者:2297

如何实现对中效果:

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; () ) ) ) )。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。