CSS 中的波浪下划线

A wavy underline in CSS

我可以像这样创建波浪下划线吗:
我只能得到一个实心边框:

.err {
  border-bottom:1px solid red;
  display: inline-block;
}
<div>A boy whose name was Peter was <div class="err">woking</div> down the street</div>

您可以使用 CSS text-decoration-style 属性.

-webkit-text-decoration-style: wavy;
-moz-text-decoration-style: wavy;
text-decoration-style: wavy;

然而,this is limited to Firefox and Safari。您可能需要考虑改用图片。

您可以在 link 上使用 :after 伪元素并设置波浪图像的 repeat-x 背景。 您也可以使用 border-image CSS3 属性,但这是 not fully supported 对于旧浏览器

没有背景图片:

.err {
  display: inline-block;
  position: relative;
}
.err:before {
  content: "~~~~~~~~~~~~";
  font-size: 0.6em;
  font-weight: 700;
  font-family: Times New Roman, Serif;
  color: red;
  width: 100%;
  position: absolute;
  top: 12px;
  left: -1px;
  overflow: hidden;
}
<div>A boy whose name was Peter was
  <div class="err">woking</div> down the street</div>

带背景图片:

.err {
    display: inline-block;
    position:relative;
    background: url(http://i.imgur.com/HlfA2is.gif) bottom repeat-x;
}
<div>A boy whose name was Peter was <div class="err">woking</div> down the street</div>

下面是您可以在没有图像的情况下实现这一目标的方法之一的示例。根据需要调整。

.err {
  border-bottom:2px dotted red;
  display: inline-block;
  position: relative;

}

.err:after {
  content: '';
  width: 100%;
  border-bottom:2px dotted red;
  position: absolute;
  font-size: 16px;
  top: 15px; /* Must be font-size minus one (16px - 1px) */
  left: -2px;
  display: block;
  height: 4px;

  
  }
<div>A boy whose name was Peter was <div class="err">woking</div> down the street</div>