html - 在多行文本下绝对定位一行

标签 html css

我有一个非常简单的设置,我在 :after psuedo 元素中的所有 A href 下添加了一个 2px 高的“线”。

问题是我希望该行位于 a html 标记内每行文本的下方,而不仅仅是 a 的底部。

有没有办法让 :after 出现在每行文本下面,而不是整个文本 block ?

我没有使用文本修饰:下划线;是因为我想控制下划线的外观/样式,然后在悬停时为其设置动画。

HTML:

<a href="link.com">Some text here that will wrap onto 2 lines because it is quite long</a>

CSS:

a:after {
    content: "";
    position: absolute;
    width: 100%;
    height: 2px;
    bottom: 0;
    left: 0;
    background-color: currentColor;
    -webkit-transform: scaleX(1);
    transform: scaleX(1);
}

我希望 :after 行出现在两行文本的下方,当它换行时(因此看起来像一个常见的链接下划线),但当前它只显示在整个 A block 下方......

我要:

Some text that will wrap onto 2 lines 
_____________________________________

because it is quite long.
_________________________

我得到的:

Some text that will wrap onto 2 lines 

because it is quite long.
           _____________

最佳答案

好的,可能不是最优雅的解决方案,但您可以尝试使用渐变背景:

.gradientLink{  
  line-height: 50px;
  text-decoration: none;
  color: #212121;
  padding: 14px 0;
  background: linear-gradient(0deg, red 1px, white 1px);
}

https://codepen.io/giannidk/pen/MZGPNX

关于html - 在多行文本下绝对定位一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54073334/

相关文章:

html - 我想知道如何在数据列表项上应用 css。我想更改高度和字体大小

html - CSS block 属性会影响 HTML 的良构性吗?

html - 我如何使用 Nokogiri 解析 Google 搜索结果?

html - 每 2 行后制作一个 html 表格的边框

html - Fieldset 中的 DIV 层在后台打开而不是前景

javascript - 网站上的移动菜单问题

html - 使 CSS3 动画在浏览器中更可靠

html - 当其他元素获得焦点时,CSS 选择元素

javascript - 使用java脚本在onClick事件中更改菜单选项卡的颜色

html - 如何将 z-index 与 float 一起使用?