javascript - 如何居中预加载器(移动)?
问题描述
尝试了很多不同的解决方案,但由于某种原因,我的预加载器无法在移动设备上居中。在桌面/移动风景上很好,但每当我在移动肖像上时......它不是居中的。
CSS:
.load-screen{
background-color: white;
opacity: 1;
position: fixed;
margin-left: auto;
z-index: 1000;
width: 100%;
height: 100vh;
transition: 0.4s ease-in;
}
.loading-image{
display: block;
width: 100%;
margin-top: 15vw;
margin-left: auto;
animation-name: loadscreen;
animation-duration: 3.5s;
animation-iteration-count: infinite;
align-items: center;
justify-content: center;
text-align: center;
}
截图: 手机截图
解决方案
使用 display:flex 将使里面的任何东西成为一个弹性项目。justify-content: center 将项目从左到右居中对齐项目: center 将项目从上到下居中。
见小提琴:http: //jsfiddle.net/fm3xvzc8/
.load-screen{
background-color: white;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
opacity: 1;
position: fixed;
margin-left: auto;
z-index: 1000;
width: 100%;
height: 100vh;
transition: 0.4s ease-in;
}
.loading-image{
display: block;
width: 100%;
// margin-top: 15vw; The margins aren't necessary
// margin-left: auto; The margins aren't necessary
animation-name: loadscreen;
animation-duration: 3.5s;
animation-iteration-count: infinite;
}
推荐阅读
- android - 我们可以在 Android 上将“dpm set-owner”用于有根/无根 Android 上的生产设备吗
- reactjs - 尝试将文件夹添加到 Firestore
- reactjs - 如何将查询参数推送并用于此页面的反应?
- python - 使用带有restframework的Django Pagination转到特定页面
- neo4j - 如何检查 Neo4j 全文索引是否存在?
- json - 从外部数据到 Google 表格的 API 连接:JSON 解析错误
- python - PyCharm 在 '__init__.pyi | 中未解决的参考 'linspace' __init__.pyi'
- c# - 使用 C# 将 HTML 内容转换为常规文本
- ios - AVAudioSessionCategoryPlayback 未按预期工作
- python - 如何将 Pandas 数据框直接写入 FTP 上的 Excel 文件