gpt4 book ai didi

html - 将 div 对齐到水平中心的错误

转载 作者:可可西里 更新时间:2023-11-01 13:26:38 26 4
gpt4 key购买 nike

我试图通过这种方式使 div 居中:div 高度为:35.3em边距顶部:计算(50% - (35.3em/2))

错误发生在我调整浏览器的宽度时,div 以某种方式改变了他的水平位置

我网站的网址:http://cherry-rocks.herokuapp.com

最佳答案

看到你使用相对定位,你也可以使用 top 而不是 margin-top 来明确地将元素定位到中心。使用 top: calc(50% - (35.3em/2)) 而不是 margin-top 或 display: flex 在父级和 margin: auto 在 child 上,如果你愿意使用 flexbox。

关于html - 将 div 对齐到水平中心的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37102672/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com