始终将固定项居中[重复]

问题描述 投票:1回答:1
如何将带有红色边框的固定元素水平居中?我为视觉提示添加了3个多维数据集。

中心我的意思是中心立方体位于视口中心(并在调整视口大小时停留在此中心),并且如有必要,从左和右切除其余的固定元素。

这必须是老式的,即

no flexbox。

#element { width: 120%; height: 200px; position: fixed; left: 0; top: 0; border: 2px dashed #ec6161; } #children { display: flex; justify-content: space-around; align-items: center; height: 100%; } .child { width: 50px; height: 50px; border: 2px dashed #888; postion: absolute; }
<div id="element">
  <div id="children">
    <div class="child left"></div>
    <div class="child center"></div>
    <div class="child right"></div>
  </div>
</div>
css
1个回答
1
投票
#element { width: 120%; height: 200px; position: fixed; left: 0; top: 0; border: 2px dashed #ec6161; margin-left: -10%; }
您可以将margin-left: -10%添加到您的#element组件中
© www.soinside.com 2019 - 2024. All rights reserved.