Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make first column of a row black and second column red

Tags:

css

I would like to give a css class to a row and i would like to make the first column black and the second column red. I dont want to use colgroup because this is a row specific action not whole table should be effected.

like image 372
rematnarab Avatar asked Mar 04 '12 13:03

rematnarab


People also ask

How do I change the background color of a column?

How do I change the background color for a column? To change the background color for a column, click on the column header in the grid and change the background color from the Font Control option available in Task menu.

How do I freeze the first two columns in an HTML table?

To freeze the row/column we can use a simple HTML table and CSS. HTML: In HTML we can define the header row by <th> tag or we can use <td> tag also. Below example is using the <th> tag. We also put the table in DIV element to see the horizontal and vertical scrollbar by setting the overflow property of the DIV element.

How do I freeze the first column in a table?

Freeze columns and rows Select the cell below the rows and to the right of the columns you want to keep visible when you scroll. Select View > Freeze Panes > Freeze Panes.


2 Answers

You could use:

td { color: black; }
td:nth-child(2) { color: red; }
like image 191
Qtax Avatar answered Sep 22 '22 06:09

Qtax


This is possible without CSS3 !

Sample
http://jsfiddle.net/Q3yu5/1/

CSS

tr.special_row td {
    background-color: #000;
}

tr.special_row td + td {
    background-color: #f00;
}

tr.special_row td+td+td {
    background-color: #fff;
}

HTML

<table>
<tr class="special_row">
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
</tr>
<tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
</tr>
</table>
like image 20
Smamatti Avatar answered Sep 18 '22 06:09

Smamatti