首页 > 解决方案 > 如何垂直对齐页脚中的文本并从 ::after 内容中删除下划线

问题描述

所以我有两个问题:

1. 如何将页脚中的文本垂直对齐两行或多行?

(我将行高与页脚的高度对齐以对齐一行,但它在两行或多行之间留下了巨大的间隙)

2. 如何从 CSS ::after 内容中删除下划线,但将其保留在文本下方。

(所以所有链接都会像最后一个一样悬停)

HTML 和 CSS

    footer {
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      min-height: 50px;
      line-height: 50px;
      text-align: center;
      margin-top: auto;
      margin-bottom: auto;
      color: white;
      background-color: #232323;
    }
    
    footer a {
      cursor: pointer;
    }
    
    footer a:hover {
      text-decoration: underline;
    }
    
    footer a:not(:last-child)::after {
      content: " | ";
      cursor: default;
    }
<footer>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
    <a>Link</a>
</footer>

JSFIDDLE
https://jsfiddle.net/qmbbtmb5/

标签: htmlcssvertical-alignment

解决方案


position: absolute您可以通过将css 属性添加到:after伪选择器来使其按您想要的方式工作。尝试像这样调整您的 css 代码。

footer {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  min-height: 50px;
  text-align: center;
  line-height: 1.5;
  margin-top: auto;
  margin-bottom: auto;
  color: white;
  background-color: #232323;
  padding: 30px 0;
}

footer a {
  cursor: pointer;
  display: inline-block;
  position: relative;
  margin: 0 5px;
}

footer a:hover {
  text-decoration: underline;
}

footer a:not(:last-child)::after {
  content: " | ";
  cursor: default;
  position: absolute;
  top: 0;
  right: -10px;
}

推荐阅读