我有一个设置了样式的锚元素.在锚点换行到下一行之前,这种方法工作得很好.然后,它只将该样式应用于两条直线的垂直交点.我怎样才能在两条线上都包起来呢?

a {
  text-decoration: none;
  word-wrap: break-word;
  position: relative;
  border: 1px black solid
}

a:hover::before {
  bottom: 0;
  height: 95%;
}

a::before {
  content: '';
  background: orange;
  position: absolute;
  left: 0;
  bottom: 3px;
  width: 100%;
  height: 6px;
  z-index: -1;
  transition: all .3s ease-in-out;
}
<a href="">How can I apply the styling so it wraps on both lines?</a>
<br><br>
<a href="">How can I apply the styling so it wraps on both lines? How can I apply the styling so it wraps on both lines? How can I apply the styling so it wraps on both lines?</a>

推荐答案

使用渐变

a {
  text-decoration: none;
  word-wrap: break-word;
  border: 1px black solid;  
  background: linear-gradient(orange 0 0) left 0 bottom 3px/100% 6px no-repeat
}
<a href="">How can I apply the styling so it wraps on both lines?</a>
<br><br>
<a href="">How can I apply the styling so it wraps on both lines? How can I apply the styling so it wraps on both lines? How can I apply the styling so it wraps on both lines?</a>

Html相关问答推荐

按钮的字体重量在鼠标悬停时随过渡而变化

你能让Cypress测试为p—fileUpload做文件上传吗?

我需要主页按钮出现在中间

网格容器中的定心元件

只有一行上有溢出的CSS网格

Tumblr博客:如何修复提交页面和询问页面框列计数问题?

如何仅 Select 与子代CSS类匹配的第一个元素

在FlexBox中将div拉伸到父div的完全高度

将2个Flex列合并为1个交替子列

如何在悬停时更改同级元素 CSS

在span中添加

为 HTML5 文本字段设置最后六位正则表达式模式

当我们在vue中使用截断大文本时如何显示标题属性?

如何使用CSS Select 同级元素的::before伪元素?

a with