我想使一个 div
坚持在屏幕的顶部没有任何影响其他元素,其子元素在中心。
.parent {
display: flex;
justify-content: center;
position: absolute;
}
<div class="parent">
<div class="child">text</div>
</div>
当我添加 position: absolute
行时,justify-content: center
变得无效。它们相互冲突吗? 解决办法是什么?
剪辑
Thanks guys it's the problem of parent width. But I'm in React Native, so I can't set width: 100%
. Tried flex: 1
and align-self: stretch
, both not working. I ended up using 维度 to get the full width of the window and it worked.
剪辑
至于更新版本的 React Natural (我使用的是0.49) ,它接受 width: 100%
。