【发布时间】:2021-04-04 16:25:32
【问题描述】:
我有这个<h4> 标签:
<h4>
A <a href="https://openjdk.java.net/">Java</a> and <a href="https://kotl.in">Kotlin</a> coder.
</h4>
应用了这个 CSS(继承自 body):
body {
font-family: jetbrains-mono;
background-color: #444;
color: #EEEEEE;
font-size: 18px;
max-width: 650px;
line-height: 1.2;
display: grid;
align-items: center;
margin: auto auto;
}
仅使用 align-content: center 会产生相同的结果。
问题是,如果我使用弹性框而不是网格来使文本居中,如下所示:
display: flex;
align-items: center;
justify-content: center;
我该如何解决这个问题? 完整的 html 文件在这里:https://github.com/TheOnlyTails/theonlytails.com/blob/main/index.html 完整的 css 文件在这里:https://github.com/TheOnlyTails/theonlytails.com/blob/main/style.css
【问题讨论】: