我为我的web应用添加了一个登陆页面,所以当它从服务器加载数据时,会显示一个带有加载图像和说明的登陆页面。
<div class="map_view">
<!-- shown only when data is not available -->
<div class="loading_screen">
<img src="/img/loading_boys.gif"/>
<h2>Connecting to the the network ...</h2>
</div>;
</div>
loading screen
的 div 在 div map_view
上方。我想将图像和 <h2>
居中在其父 div 上。我可以使用 text-align: center;
水平居中。但是我找不到垂直居中的方法。我还想使其兼容不同的屏幕尺寸,因此无论在哪种设备上,加载 div 都始终位于其父 div 的中心。我尝试在
map_view
中使用 display: table;
,并在 loading_screen
上使用 display: table-cell; vertical-align: middle;
,但是谷歌地图消失了,只剩下背景颜色。
flex-direction: column
。请查看我回答中的修改后的代码块。 - Michael Benjamin