如何让我的页脚文本垂直居中? [重复]

问题描述 投票:-3回答:2

这个问题已经在这里有一个答案:

footer {
  text-align: center;
  color: #FFF;
  position: fixed;
  bottom: 0px;
  width: 100%;
  height: 90px;
  background-color: #464646;
}
<footer>
  &copy; Name
</footer>

我想我的名字是在页脚的正中心。但它只会在中心顶部。有人能回答这个最基本的问题?尽量不要让你的答案困难,因为我只是一个初学者。

html css footer
2个回答
2
投票

问东西前,请网上查询,如果你的问题有任何答案。你可以通过很多方式垂直对齐。

这里的另一个人告诉你line-height.DO做不设置行高度对齐中心回答。这是一个非常不好的做法。因为如果由于某种原因,你的文字去行,一切都将中断。

尽量让事情会工作在几乎任何情况。

然而,在这里与显示一个例子:弯曲;

footer {
  display: flex;
  text-align: center;
  justify-content: center;
  align-items: center;
  color: #FFF;
  position: fixed;
  bottom: 0px;
  width: 100%;
  height: 90px;
  background-color: #464646;
  vertical-align: middle;
}
<footer>
       <span>&copy; Name </span>
</footer>

0
投票

一个快速简便的方法是将之躯line-height设置为相同的值height,如下图所示:

footer {
  text-align: center;
  color: #FFF;
  position: fixed;
  bottom: 0px;
  width: 100%;
  height: 90px;
  background-color: #464646;
  line-height: 90px;
}
<footer>
  &copy; some Name
</footer>
© www.soinside.com 2019 - 2024. All rights reserved.