我目前设置了一个 ReactJS + React Router 项目,并且在 Chrome 开发工具中的元素下显示:
<body>
<div class="wrapper">
<div data-reactroot>
<div>
<div class="container">Center Me</div>
</div>
</div>
</div>
</body>
有样式,没有 class="wrapper"
:
.container {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
然而 <div class="container">Center Me</div>
保持在顶部并水平居中但不是垂直居中。
我检查了那个 div 的大小,它非常短,但占据了浏览器页面的整个宽度。
我可能做错了什么?我怎样才能居中 <div class="container">Center Me</div>
?我什至尝试将 100% for width and height
设置为更高的级别,但仍然无法正常工作。
原文由 Jo Ko 发布,翻译遵循 CC BY-SA 4.0 许可协议
只是:
或CSS: