html - 在全高子 div 中垂直居中文本
问题描述
我试图在一个全高的子 div 内垂直居中文本,但是当我这样做时,它在底部有额外的间距。如果没有额外的间距,我怎么能做到这一点?我想要一个导航和一些垂直居中的文本,但没有额外的间距。
html {
height: 100%;
}
body {
margin: 0;
min-height: 100vh;
}
h1 {
margin: 0;
padding: 0;
}
.landing {
background: url(bg.svg);
height: 100vh;
}
.landing-content {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.landing-content h1 {
color: white;
margin: 0;
}
.app {
background-color: black;
height: 100vh;
color: white;
}
<div class="app">
<div class="logo">
<h1>logo</h1>
</div>
<div class="landing">
<div class="landing-content">
<h1>hi, i'm jordan</h1>
</div>
</div>
</div>
解决方案
更改 .app 类如下。
.app {
background-color: black;
height: auto;
color: white;
}
推荐阅读
- javascript - 在 React 中导入 prop 数组值?
- r - 如何将变量从整数转换为基数 R 中的字符串?
- java - Ear 文件不包含子模块的依赖关系
- asp.net - 升级到 ASP.NET Zero (Angular) 中的 FontAwesome Pro/显示为正方形的远距离图标
- c++ - 如何在 Mac 上处理 VS Code 中的 C++ 头文件#include 错误?
- ios - 世博会推送通知 iOS APNS
- reactjs - React 放置自动完成多个类型的问题(Nextjs)
- c# - 我想通过单击将按钮移动到堆栈面板的最顶部
- python - 根据时间戳将数据帧拆分为多个子数据帧
- lustre - 如何为 MOFED 正确重建 Lustre