You do not need to change the structure of the tables. They comply with the HTML standard, and there is a solution using pure CSS to get the effect you requested. Using :first-child and :last-child in the thread , tbody and tfoot table wrap elements, you can only select cells in the corners of the entire table. Here are the details.
The selector * simply selects all the elements. But > means only apply the effect to direct children. Therefore, we extract all the elements of the table listed above. There are no deeper children with a table , like tr or td .
To include both th and td , we again use * together with > to retrieve all the direct children of the table row, regardless of whether they are th or td . You could instead select a selector for both.
.unit > *:first-child > tr:first-child > *:first-child, .unit > *:first-child > tr:first-child > *:last-child, .unit > *:last-child > tr:last-child > *:first-child, .unit > *:last-child > tr:last-child > *:last-child { background: red; }
I created a working demo based on the code you provided on this subject.
In any case, you did not tell us why you need it, and there may be a better way to achieve this. For example, if you want to provide round corners, you can apply the effect to the table element of the wrapper div.
danijar Apr 11 '13 at 16:12 2013-04-11 16:12
source share