将 div 水平居中对齐时出现错误
Bug with aligning div to center horizontal
我试图通过这种方式使 div 居中:
div 身高是:35.3em
上边距:计算(50% - (35.3em / 2))
当我玩浏览器的宽度时,这个错误发生了,div不知何故改变了他的水平位置
我网站的 URL : http://cherry-rocks.herokuapp.com
看到你使用相对定位,你也可以使用 top 而不是 margin-top 来明确地将元素定位到中心。如果您愿意使用 flexbox,请在父级上使用 top: calc(50% - (35.3em / 2))
而不是 margin-top 或 display: flex
,在子级上使用 margin: auto
。
我试图通过这种方式使 div 居中: div 身高是:35.3em 上边距:计算(50% - (35.3em / 2))
当我玩浏览器的宽度时,这个错误发生了,div不知何故改变了他的水平位置
我网站的 URL : http://cherry-rocks.herokuapp.com
看到你使用相对定位,你也可以使用 top 而不是 margin-top 来明确地将元素定位到中心。如果您愿意使用 flexbox,请在父级上使用 top: calc(50% - (35.3em / 2))
而不是 margin-top 或 display: flex
,在子级上使用 margin: auto
。