div叠加在上方居中对齐_div居中上下对齐

div叠加在上方居中对齐_div居中上下对齐,第1张

div叠加在上方居中对齐_div居中上下对齐 方法一#wrap{ position:absolute; width:300px; height:200px; top:50%; left:50%; transform:translate(-50%,-50%) ; background:#009688; } 若是下面的代码,其结果就是错误的#wrap{ width:300px; height:200px; margin-top:50%; margin-left:50%; transform:translate(-50%,-50%) ; background:#009688; }原因:当margin设置成百分数的时候,其top right bottom left的值是参照父元素盒子的宽度进行计算方法二直接用d性盒布局,作用于父元素上实现parent{ width:100%; height:100vh; display:flex; justify-content: center;//子元素水平居中 align-items: center;//子元素垂直居中

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/tougao/651080.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-17
下一篇 2022-04-17

发表评论

登录后才能评论

评论列表(0条)

保存