8

I'm having trouble "clearing" a line-through that I'm using on a table row. I don't want the line-through effect on the link. I'm changing the tr class dynamically with Javascript so I would like to keep it as simple as possible.

My current code:

HTML:

<table>
<tr class="table-item">
<td>Text</td>
<td><a href="#">Delete item</a></td>
</tr>
</table>

CSS:

.table-item td {
text-decoration: line-through;
}
.table-item a {
text-decoration: none;
}

Any suggestions?

Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
frapser
  • 83
  • 1
  • 1
  • 3
  • 3
    [MDC](https://developer.mozilla.org/en/CSS/text-decoration#Notes) says: “Text decorations draw across descendant elements. This means that it is not possible to disable on a descendant a text decoration that is specified on one of its ancestors.” – Marcel Korpel Apr 26 '11 at 14:54
  • That is indeed good information, thank you. – frapser Apr 26 '11 at 16:09

4 Answers4

6

I was playing with it in jsFiddle. Seems like the only way to do it is to wrap the other content that you want the line-through on in another element, like a span.

Update: code from jsFiddle, as requested:

<table>
  <tr class="table-item">
    <td><span>Text</span></td>
    <td><a href="#">Delete item</a></td>
  </tr>
</table>

CSS:

.table-item td span {
  text-decoration: line-through;
}
Austin Taylor
  • 5,267
  • 21
  • 28
1

I am not sure, why anyone has not pointed out. This is actually possible.

Here is the link to fiddle

JSFiddle

Adding display: inline-block on element which you dont want to show line-through will do the trick.

Try:

.table-item td {
  text-decoration: line-through;
}
.table-item a {
  text-decoration: none;
  display: inline-block;
}
Gags
  • 3,359
  • 8
  • 37
  • 84
0

Depending on your browser requirements (won't work in old IE) you can use:

.table-item td:first-child {
  text-decoration: line-through;
}
jeroen
  • 88,615
  • 21
  • 107
  • 128
0

Is using span, out of the question?

a {
    text-decoration: none;  
}
td span{
text-decoration: line-through;
}

<table>
<tr class="table-item">
<td><span>Text</span></td>
<td><a href="#">Delete item</a></td>
</tr>
</table>

Or are you strictly using code injection to style the strikethrough?

Tim Joyce
  • 4,304
  • 4
  • 31
  • 46