CSS中的波浪下划线

时间:2015-01-26 14:35:32

标签: html css html5 css3 underline

我可以创建一个波浪下划线:http://i.imgur.com/aiBjQry.png
我只能得到一个稳固的边界:



.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>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:33)

没有背景图片:

&#13;
&#13;
.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;
}
&#13;
<div>A boy whose name was Peter was
  <div class="err">woking</div> down the street</div>
&#13;
&#13;
&#13;

使用背景图片

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

答案 1 :(得分:27)

下面是一个没有图像的方法之一的示例。根据需要进行调整。

&#13;
&#13;
.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;

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

答案 2 :(得分:10)

您可以使用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。您可能需要考虑使用图像。

答案 3 :(得分:0)

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