2012-06-18 22 views
2

可能重複:
How do I get this CSS text-decoration override to work?我不能重寫文字裝飾爲無?

Chrome和Firefox的陰謀挫敗我試圖與該行通過文字修飾一個TD,有時跨度禁用,像這樣:

<style type="text/css"> 
tr.st td { 
    text-decoration: line-through; 
} 

tr.st td span.unstrike{ 
    text-decoration: none; 
    background:yellow; 
} 

tr.st td span#unstrike-id{ 
    text-decoration: none; 
    background:yellow; 
} 

tr.st td span.unstrike-important{ 
    text-decoration: none ! important; 
    background:yellow; 
} 

</style> 


<table border> 
    <tbody> 
     <tr> 
     <td>normal</td> 
     </tr> 
     <tr class="st"> 
     <td>struck out</td> 
     </tr> 

     <tr class="st"> 
     <td>struck out <span class="unstrike">unstrike class: shouldn't I be normal?</span></td> 
     </tr> 

     <tr class="st"> 
     <td>struck out <span id="unstrike-id">unstrike-id identifier. Shouldn't I be normal?</span></td> 
     </tr> 

     <tr class="st"> 
     <td>struck out <span class="unstrike-important">unstrike-important: shouldn't I be even more normal?</span></td> 
     </tr> 
    </tbody> 
    </table> 

我眯着眼睛看規範,我不明白。

文本破壞的特例?是什麼賦予了?

演示here

+0

哇,這很有趣,看起來'文字修飾'被應用到整個道明的內容,而忽略了它下面的任何東西。從來沒有見過。 –

+1

看到這個答案:http://stackoverflow.com/a/1261974/698179 - 在你所有的'td'中放置'span'可能會更好,並且將樣式單獨作爲子元素應用。 –

+0

是的,我現在看到它,雖然我認爲這是最好的先例:http://stackoverflow.com/questions/1823341/how-do-i-get-this-css-text-decoration-override-to-work/1823388#1823388 – djsadinoff

回答

0

如果你有一個特定的順序使用屬性,其行裝修,您可以使用:nth-child()

或者嘗試添加線裝飾跨越,而不是TD。看看我的例子:jsfiddle

0

該透視應用於表格單元格,而不是其內容。類似的情況是將邊界應用於<td>。刪除跨度上的邊框不會阻止td上的邊框閃爍。

您可以爲該跨度添加不透明的背景。


添加:

position: relative; 
display: inline-block; 
top: 0px; 

seems to fix it.

+0

大部分時間我都在從規範中尋找一些解釋爲什麼會這樣。有很多修復。你的確很有趣。但是,如果沒有深入理解它爲什麼會起作用,爲什麼使用內聯塊,而是使用普通塊(比如說div)卻不行,我會猶豫不決。 – djsadinoff