Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select columns including colspans in a table?

Assume I have a table that looks like this:

<table>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td colspan="2"></td>
    <td></td>
    <td colspan="2"></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td colspan="2"></td>
    <td></td>
    <td colspan="2"></td>
  </tr>
</table>

How do I select all the cells in the fourth column, including the td[colspan="2"] that spans to it with CSS?

like image 751
Frinsh Avatar asked Oct 16 '14 15:10

Frinsh


People also ask

How do I select a specific column in a table in HTML?

In Mozilla Firefox, users may highlight only certain rows, columns, or cells of an HTML table by holding down the Ctrl on the keyboard and click each cell individually.

What is row span and column span?

The rowspan and colspan are the attributes of <td> tag. These are used to specify the number of rows or columns a cell should merge. The rowspan attribute is for merging rows and the colspan attribute is for merging columns of the table in HTML.

How do you split TD into two columns?

Use an extra column in the header, and use <colspan> in your header to stretch a cell for two or more columns. Insert a <table> with 2 columns inside the td you want extra columns in.

How do I merge 3 columns in a table in HTML?

To merge table columns in HTML use the colspan attribute in <td> tag. With this, merge cells with each other. For example, if your table is having 4 rows and 4 columns, then with colspan attribute, you can easily merge 2 or even 3 of the table cells.


1 Answers

It's not pretty but can be done with multiple selectors: http://jsfiddle.net/r4atjtfx/1/

tr:first-child td:nth-child(4),
tr:first-child + tr td[colspan="2"] ~ td[colspan="2"],
tr:last-child td:nth-child(3) {
    color: orange;
}

But to answer your question no selector exists to target different table columns.

like image 123
Adrift Avatar answered Oct 08 '22 04:10

Adrift