2012-01-04 23 views
11

我的HTML是:变化划掉文字颜色

<html> 
<body> 
    <div id="example">this is example</div> 
</body> 
<html> 

我的CSS是:

#example{text-decoration: line-through;color:#ccc;} 

我收到了,把这样
out-put image
但我想像这样
i am trying to do like this但我不能。帮助我这样做。

+3

http://stackoverflow.com/questions/1107551/css-strikethrough-different-color- from-text – 2012-01-04 08:22:57

回答

20

颜色适用于直通和文本。你需要像巢一样嵌套。

<span style="text-decoration: line-through; color: red;"> 
<span style="color: #CCC;">text with red linethrough and black text</span> 
</span> 

来源:http://www.savio.no/artikler/a/335/different-font-color-than-line-through-color-with-css

+1

如果您给出原始答案的链接,那就太好了。 http://stackoverflow.com/a/1107556/293712 – Maheep 2012-01-04 08:23:03

+0

然后这个链接参考将有所帮助。它是源于信誉的好习惯。 – Maheep 2012-01-04 08:26:31

+1

已更新的答案。 – 2012-01-04 08:34:18

0

这是一个例子,它工作正常。

HTML:

<div id="example"> 
    this is example 
    <span></span> 
</div> 

CSS:

#example{ 
    color:#ccc; 
    font-size: 20px; 
    position: relative; 
    display: inline-block; 
} 

#example span { 
    position: absolute; 
    width: 100%; 
    border-top: 1px solid red; 
    left: 0; 
    top: 50%; 
} 

http://jsfiddle.net/amkrtchyan/RHPHX/1/

+0

不工作时,有一个以上的线,虽然 – martin 2014-11-19 11:45:38