Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Table Row border color with border-collapse

I've seen several posts here on the subject, and I've read the W3C spec on border style conflict-resolution (and admit, I don't fully get it), and I'm not sure how to achieve what I want.

On row hover, I want to change the color of the border around the row. I have surmised the best cross-browser way to do it is change the td border colors in that row. However, I can't seem to execute it in a way where the row's top border also changes.

Here's my CSS:

#dataGrid table {
border: 1px solid #cacac8; /* I've tried it with and without this border setting */
table-layout: fixed;
border-collapse: collapse;
}

#dataGrid td {
    border: 1px solid #cacac8;
    padding: 8px 11px 7px 11px;
    text-align: left;
}

#dataGrid .cellHovered {
    border-top: 1px solid #425474;
    border-bottom: 1px solid #425474;
}

#dataGrid .cellFirstHovered {border-left: 1px solid #425474;}
#dataGrid .cellLastHovered {border-right: 1px solid #425474;}

and my JQuery:

$('div#dataGrid tr.dataRow').hover(
        function () {
            $(this).children('td').addClass('cellHovered');
            $(this).children('td:first').addClass('cellFirstHovered');
            $(this).children('td:last').addClass('cellLastHovered');
        },
        function() {
            $(this).children('td').removeClass('cellHovered');
            $(this).children('td:first').removeClass('cellFirstHovered');
            $(this).children('td:last').removeClass('cellLastHovered');
    });
like image 960
Gregir Avatar asked Oct 29 '11 22:10

Gregir


People also ask

Which CSS property can be used for collapsing the border between table cells?

Choose the CSS property that can be used for collapsing the borders between table cells? Explanation: The border-collapse property sets whether the table borders are collapsed into a single border or detached as in standard HTML.

What value for Border-collapse property detaches border between cells of a table?

separate: It is the default value that separates the border of the table cell.


1 Answers

Firstly, you might be better off not using jQuery and instead using pure CSS:

#datagrid tr.datarow:hover td {
    border: whatever;
}

Next, since you're using 1px borders, try this trick:

#datagrid tr.datarow:hover td {
    border-style: double;
}

Since double is "more distinct" then solid, its colour takes precedence over cells around it, and looks identical to solid anyway ;)

like image 66
Niet the Dark Absol Avatar answered Oct 21 '22 12:10

Niet the Dark Absol