CSS 中的波浪下划线[重复]

问题描述 投票:0回答:4

我可以创建一个波浪下划线吗: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>

html css underline
4个回答
42
投票

没有背景图片:

.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>


34
投票

下面是无需图像即可实现此目的的方法之一的示例。根据需要调整。

.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>


22
投票

您可以使用 CSS

text-decoration-style
属性:

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

这适用于所有主要浏览器(IE 除外 - 如果您需要支持,那么您可能需要考虑使用图像)


0
投票

您可以在链接上使用

:after
伪元素并设置波形图像的重复 x 背景。 您还可以使用
border-image
CSS3 属性,但这对于旧浏览器不完全支持

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.