I have a table and I want to replace "1" by "X" and "0" by "". Is it possible with CSS ?
<table>
<tr>
<td>1</td>
<td>0</td>
</tr>
</table>
I have a table and I want to replace "1" by "X" and "0" by "". Is it possible with CSS ?
<table>
<tr>
<td>1</td>
<td>0</td>
</tr>
</table>
This sounds like a job for jQuery.
HTML
<table>
<tr>
<td>1</td>
<td>0</td>
</tr>
</table>
jQuery
$('td').each(function(){
if ($(this).text() == '1') { $(this).text('X'); }
if ($(this).text() == '0') { $(this).text(''); }
});
You could do something like this (DEMO):
td {
font-size:0;
}
td:first-child:after {
content: "X";
font-size: 14px;
}
But thats ugly and I personally prefer javascript for such a task. So do not use this solution. It's just not the task of css to do something like that.
In jQuery it would be as easy as this:
$('td:contains("1")').text('X');
$('td:contains("0")').text('');
And not to forget in plain javascript:
var tds = document.getElementsByTagName('td');
for(var i = 0; tds[i]; i++) {
if(tds[i].innerHTML == '1') tds[i].innerHTML = 'X';
if(tds[i].innerHTML == '0') tds[i].innerHTML = '';
}
You could do this if you're sure that you want the exact behavior by using just CSS
td:first-child:after
{
content:"X";
}
td:first-child + td:after
{
content:"";
}
But for this to work, you must have empty columns..
<table>
<tr>
<td></td>
<td></td>
</tr>
</table>
EDIT: For the sake of completion, if your html is as simple as it looks in the question, I would go with the above approach but if your html is more dynamic & unpredictable, obviously you need to opt for javascript/jQuery approach.
You can do this with some visibility
, after
and content
DEMO http://jsfiddle.net/kevinPHPkevin/hJyd8/
td:nth-child(1) {
visibility: hidden;
}
td:nth-child(1):after {
content:"2";
visibility:visible;
}
td:nth-child(2) {
visibility: hidden;
}
td:nth-child(2):after {
content:"''";
visibility:visible;
}