【问题标题】:How can I vertically align text in my footer and also remove underline from ::after content如何垂直对齐页脚中的文本并从 ::after 内容中删除下划线
【发布时间】:2018-05-07 00:16:16
【问题描述】:

所以我有两个问题:

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/

【问题讨论】:

标签: html css vertical-alignment


【解决方案1】:

您可以通过将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;
}

【讨论】:

  • 非常感谢。你知道如何解决我的第一个问题吗?
  • 我添加了顶部和底部 padding 并减少了您的 line-height 以使您的页脚链接垂直居中对齐。
  • 哦,我错过了,因为我刚刚复制了最后一个 CSS 规则。非常感谢!
猜你喜欢
  • 2014-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-19
  • 1970-01-01
  • 1970-01-01
  • 2019-01-28
  • 1970-01-01
相关资源
最近更新 更多