HTML元素del、strike或s都可以用于文本删除效果。例子:

<del>del</del>

....德尔给:

<strike>strike</strike> and <s>strike</s>

....给予:罢工和罢工

值为line-through的CSS text-decoration属性也可以类似地使用。代码…

<span style='text-decoration:line-through'>
    text-decoration:line-through
</span>

...也会渲染成这样:文本装饰:线贯穿

但是,划线通常与文本的颜色相同。

CSS可以用来使线的颜色不同吗?


当前回答

如果你不关心internet explorer\edge,那么最简单的方法来实现不同的颜色擦除将是使用CSS属性: 文字装饰-色彩配合文字装饰:贯穿;

.yourClass {
    text-decoration: line-through !important;
    text-decoration-color: red !important;
}

—不能与Edge\Internet Explorer一起工作

其他回答

下面是一个jQuery实现的示例——感谢gojomo的回答和utype的建议(+1)

$(function(){
  //===================================================================
  // Special price strike-out text
  // Usage:
  //   Normally:    <span class='price'>$59</span>
  //   On special:  <span class='price' special='$29'>$59</span>
  //===================================================================
  $(".price[special]").each(function() {
    var originalPrice = $(this).text();
    $(this).html('<strike><span>' + originalPrice +'</span></strike> ' + $(this).attr('special'))
           .removeAttr('special')
           .addClass('special');
  });
});

CSS可以是

.price strike, .price.special { color: Red; }
.price strike span { color: Black; }

下面是一种使用渐变来伪造线条的方法。它使用多行换行,不需要额外的DOM元素。但由于它是背景渐变,所以它在文本后面……

del, strike {
  text-decoration: none;
  line-height: 1.4;
  background-image: -webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(0.63em, transparent), color-stop(0.63em, #ff0000), color-stop(0.7em, #ff0000), color-stop(0.7em, transparent), to(transparent));
  background-image: -webkit-linear-gradient(top, transparent 0em, transparent 0.63em, #ff0000 0.63em, #ff0000 0.7em, transparent 0.7em, transparent 1.4em);
  background-image: -o-linear-gradient(top, transparent 0em, transparent 0.63em, #ff0000 0.63em, #ff0000 0.7em, transparent 0.7em, transparent 1.4em);
  background-image: linear-gradient(to bottom, transparent 0em, transparent 0.63em, #ff0000 0.63em, #ff0000 0.7em, transparent 0.7em, transparent 1.4em);
  -webkit-background-size: 1.4em 1.4em;
  background-size: 1.4em 1.4em;
  background-repeat: repeat;
}

参见fiddle: http://jsfiddle.net/YSvaY/

渐变色位和背景大小取决于行高。(我使用LESS进行计算,然后使用自动修复…)

这个CSS3将使您更容易通过属性线,并工作良好。

span{
    text-decoration: line-through;
    text-decoration-color: red;
}

给你:

<style>身体 {颜色: #000;}</style> <del>&nbsp;&nbsp;<span style=“color:#999”>facebook</span>&nbsp;&nbsp;</del>

Blazemonger的回复(上面或下面)需要投票-但我没有足够的分数。

我想在一些20px宽的CSS圆形按钮上添加一个灰色条来表示“不可用”,并调整了Blazemonger的CSS:

.round_btn:after {
    content:"";    /* required property */
    position: absolute;
    top: 6px;
    left: -1px;
    border-top: 6px solid rgba(170,170,170,0.65);
    height: 6px;
    width: 19px;
}